1 #include <LiquidCrystal.h>
3 LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
10 * See https://www.quinapalus.com/hd44780udg.html to make more.
11 * Define which ones are used (max. 8) in setup().
12 * When they need to be changed at runtime, make sure the cursor is disabled
13 * and call setCursor afterwards.
15 byte char_music[8] = {0x02,0x03,0x02,0x0e,0x1e,0x0c,0x00};
16 byte char_bar_1[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x1f};
17 byte char_bar_2[8] = {0x00,0x00,0x00,0x00,0x00,0x1f,0x1f};
18 byte char_bar_3[8] = {0x00,0x00,0x00,0x00,0x1f,0x1f,0x1f};
19 byte char_bar_4[8] = {0x00,0x00,0x00,0x1f,0x1f,0x1f,0x1f};
20 byte char_bar_5[8] = {0x00,0x00,0x1f,0x1f,0x1f,0x1f,0x1f};
21 byte char_bar_6[8] = {0x00,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};
22 byte char_bar_7[8] = {0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f};
23 byte char_hbar_start_empty[8] = {0x1f,0x10,0x10,0x10,0x10,0x10,0x1f};
24 byte char_hbar_start_full[8] = {0x1f,0x10,0x17,0x17,0x17,0x10,0x1f};
25 byte char_hbar_inner_empty[8] = {0x1f,0x00,0x00,0x00,0x00,0x00,0x1f};
26 byte char_hbar_inner_half[8] = {0x1f,0x00,0x1c,0x1c,0x1c,0x00,0x1f};
27 byte char_hbar_inner_full[8] = {0x1f,0x00,0x1f,0x1f,0x1f,0x00,0x1f};
28 byte char_hbar_end_empty[8] = {0x1f,0x01,0x01,0x01,0x01,0x01,0x1f};
29 byte char_hbar_end_full[8] = {0x1f,0x01,0x1d,0x1d,0x1d,0x01,0x1f};
34 char contents[COLS * ROWS];
37 void redraw(struct terminal *term)
42 for (byte i = 0; i < COLS * ROWS; i++) {
44 lcd.setCursor(i % COLS, i / COLS);
45 lcd.write(term->contents[i]);
50 void scroll_up(struct terminal *term)
52 for (byte i = 0; i < COLS * (ROWS - 1); i++)
53 term->contents[i] = term->contents[i + COLS];
54 for (byte i = COLS * (ROWS - 1); i < COLS * ROWS; i++)
55 term->contents[i] = ' ';
60 * Special character meanings are defined here.
62 void write(struct terminal *term, char ch)
67 lcd.setCursor(term->x, term->y);
70 if (++term->y >= ROWS) {
74 lcd.setCursor(term->x, term->y);
79 term->contents[term->x + term->y * COLS] = 0x00;
80 lcd.setCursor(term->x, term->y);
82 lcd.setCursor(term->x, term->y);
86 term->contents[term->x + term->y * COLS] = ch;
88 if (++term->x >= COLS) {
90 if (++term->y >= ROWS) {
94 lcd.setCursor(term->x, term->y);
102 "Beste Mart, van\r\n"
103 "harte gefeliciteerd!"
104 "Hier een herprogram-"
105 "meerbare terminal. ";
109 lcd.createChar(0, char_music);
110 lcd.createChar(1, char_hbar_start_full);
111 lcd.createChar(2, char_hbar_start_empty);
112 lcd.createChar(3, char_hbar_inner_full);
113 lcd.createChar(4, char_hbar_inner_half);
114 lcd.createChar(5, char_hbar_inner_empty);
115 lcd.createChar(6, char_hbar_end_full);
116 lcd.createChar(7, char_hbar_end_empty);
118 lcd.begin(COLS, ROWS);
122 for (byte i = 0; i < ROWS * COLS; i++)
123 term.contents[i] = ' ';
125 for (byte i = 0; i < sizeof(message) - 1; i++)
126 write(&term, message[i]);
131 if (Serial.available()) {
132 write(&term, Serial.read());