-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserial_3codes.cpp
More file actions
89 lines (62 loc) · 1.71 KB
/
Copy pathserial_3codes.cpp
File metadata and controls
89 lines (62 loc) · 1.71 KB
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
89
#include "Arduino.h"
#include "stdlib.h"
#include "multidesktop.h"
#define LED_WORK 3
#define BUTTON_1 4
#define BUTTON_2 5
void print(const char *buffer, int ms)
{
Serial.println(buffer); delay(ms);
}
void up() { print("up pressed", 1000); }
void down() { print("down pressed", 1000); }
void led_button() { digitalWrite(LED_WORK, !digitalRead(LED_WORK)); }
void menu_button() { print("MENU", 1000); }
void show_1_screen()
{
print("MAIN DESKTOP", 0);
print("[ + ] [ - ] [ * D2]", 0);
}
void show_2_screen()
{
digitalRead(LED_WORK) ? print("LED on", 0) : print("LED off", 0);
print("[ + LED] [ * D3]", 0);
}
void show_3_screen()
{
print("LAST DESKTOP", 0);
print("[ + MENU] [ * D1]", 0);
}
#define BUTTONS 2
int8_t codes[] = { '+' , '-' };
func desktop1cb[] = { &up, &down };
func desktop2cb[] = { &led_button, 0 };
func desktop3cb[] = { &menu_button, 0 };
MultiDesktop<BUTTONS> multi_desktop( '*' , codes);
Desktop<BUTTONS> mainDesktop(&show_1_screen, desktop1cb);
Desktop<BUTTONS> secondDesktop(&show_2_screen, desktop2cb);
Desktop<BUTTONS> thirdDesktop(&show_3_screen, desktop3cb);
void setup()
{
pinMode(LED_WORK, OUTPUT);
pinMode(BUTTON_1,INPUT);
pinMode(BUTTON_2,INPUT);
digitalWrite(LED_WORK, LOW);
Serial.begin(9600);
print("HELLO", 500);
multi_desktop.add_desktop(&mainDesktop);
multi_desktop.add_desktop(&secondDesktop);
multi_desktop.add_desktop(&thirdDesktop);
multi_desktop.show();
}
void loop()
{
if (Serial.available())
{
char ch = Serial.read();
multi_desktop.button_pressed(ch);
multi_desktop.show(); // comfort if Serial print
}
//multi_desktop.show(); // if using LCD or show changed data
delay(1); // delay in between reads for stability
}