-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path04_showLetter.cpp
88 lines (81 loc) · 2.87 KB
/
04_showLetter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* File: 04_showLetter.cpp
* Author: Philippe Latu
* Source: https://github.com/platu/libsensehat-cpp
*
* This example program illustrates the senseShowRGBColoredLetter() function
* that prints a character on the LED matrix.
*
* When the function senseShowLetter() is called with no color specified,
* the character is printed with white foreground and black background.
*
* Function prototypes:
*
* void senseShowLetter(char);
* character to print -^
* void senseShowRGB565ColoredLetter(char, rgb565_pixel_t, rgb565_pixel_t);
* character to print -^ foreground -^ background -^
* void senseShowRGBColoredLetter(char, rgb_pixel_t, rgb_pixel_t);
* character to print -^ foreground -^ background -^
*
* This program asks the user to choose a character with the foreground and
* background colors. Program ends with the 'q' character.
*/
#include <iostream>
#include <iomanip>
#include <console_io.h>
#include <sensehat.h>
using namespace std;
int main() {
const rgb_pixel_t black = {.color = {0, 0, 0}};
const rgb_pixel_t white = {.color = {255, 255, 255}};
const rgb_pixel_t red = {.color = {255, 0, 0}};
const rgb_pixel_t orange = {.color = {255, 128, 0}};
const rgb_pixel_t yellow = {.color = {255, 255, 0}};
const rgb_pixel_t green = {.color = {0, 255, 0}};
const rgb_pixel_t cyan = {.color = {0, 255, 255}};
const rgb_pixel_t blue = {.color = {0, 0, 255}};
const rgb_pixel_t purple = {.color = {255, 0, 255}};
const rgb_pixel_t pink = {.color = {255, 128, 128}};
const rgb_pixel_t c_set[10] = {black, white, red, orange, yellow,
green, cyan, blue, purple, pink};
char c;
unsigned int fg, bg;
if (senseInit()) {
cout << "-------------------------------" << endl
<< "Sense Hat initialization Ok." << endl;
senseClear();
cout << "The characater 'q' ends the program." << endl;
do {
cout << "First, enter the character to print: ";
cin >> c;
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
if (c != 'q') {
cout << "Second, choose the foreground and background colors"
<< endl
<< "according to the following list:" << endl
<< "1:\tblack" << endl
<< "2:\twhite" << endl
<< "3:\tred" << endl
<< "4:\torange" << endl
<< "5:\tyellow" << endl
<< "6:\tgreen" << endl
<< "7:\tcyan" << endl
<< "8:\tblue" << endl
<< "9:\tpurple" << endl
<< "10:\tpink" << endl
<< "For instance: 2 1 print the character white on black."
<< endl
<< "Choose 2 colors: ";
cin >> fg >> bg;
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
senseShowRGBColoredLetter(c, c_set[fg - 1], c_set[bg - 1]);
}
} while (c != 'q');
cout << endl << "Waiting for keypress." << endl;
getch();
senseShutdown();
cout << "-------------------------------" << endl
<< "Sense Hat shut down." << endl;
}
return EXIT_SUCCESS;
}