-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo2.ino
137 lines (126 loc) · 4.54 KB
/
demo2.ino
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <Arduino.h>
#include <menu.h>
#include <Servo.h>
#define motionDetectPin 2
#define servo1Pin 10
#define servo2Pin 11
/**
* To be used with vt100 compatible terminal consoles like Putty, screen(linux) or TeraTerm(Windows) DO NOT USE Arduino IDE SERIAL MONITOR.
*
* Here 4 menu options are shown, the first automaticaly changes when the motion detection pin state changes
* You might move the servos connected at the setvo 1 pin and servo 2 pin using right and left arrows at the menu option
* The last option is to show user interface capabilities like text prompt, alert messaging...
* Use the arrows to navigate
*
* Arduino Menu System demo2
* -Idle <---- Shows automatic refresh capability
* -Move servo 1:90 <---- Move a servo
* -Move servo 2:90 <---- Move a servo
* -Show menu UI capabilities <---- Use UI stuff
*/
Servo myServo1;
Servo myServo2;
bool motionDetectStatus = false;
static const char * dummyMessage = "Do something here";
static const char * noMotion = "Idle";
static const char * motion = "Motion detected";
class testUiStuff : public menuOption{
public:
testUiStuff() :menuOption("Show menu UI capabilities"){}
void run(){
char myText[menuTextArrayLength];
String tmpStr = "Previous text";
strcpy(myText,tmpStr.c_str());
if(menuSystemOverTty.msgYes("(this is a msgYes)Do you really want to see my UI capabilities?")){
menuSystemOverTty.msgSmallWait("(this is a smallWait)Here we go!");
if(menuSystemOverTty.msgTxtInputSimple("(this is a msgTxtInputSimple)Enter a text:",myText,(menuTextArrayLength-1),1)){
menuSystemOverTty.userTty->println("(this will be a msgPause with text)You just wrote:");
menuSystemOverTty.msgPause(myText);
}else{
menuSystemOverTty.msgPause("aborted");
}
menuSystemOverTty.userTty->println("(this will be a msgPause no text)And so this is it, bye");
menuSystemOverTty.msgPause();
}
}
};
class testOption1 : public menuOption{
protected:
bool lastState;
public:
testOption1():menuOption(noMotion){
lastState = motionDetectStatus;
}
void run(){
menuSystemOverTty.msgSmallWait(dummyMessage);
menuSystemOverTty.msgPause();
}
bool refresh(){
if(lastState != motionDetectStatus){
lastState = motionDetectStatus;
if(motionDetectStatus){
strcpy(text, motion);
}else{
strcpy(text, noMotion);
}
return true;
}
return false;
}
};
class testOption3 : public menuOptionRangeValue{
protected:
public:
testOption3():menuOptionRangeValue("Move servo 1",0,180,90,7){}
void run(){
menuSystemOverTty.msgPause(dummyMessage);
}
bool refresh(){
if(menuOptionRangeValue::refresh()){// have the value changed?
myServo1.write(state);
return true;
}
return false;
}
};
class testOption4 : public menuOptionRangeValue{
protected:
public:
testOption4():menuOptionRangeValue("Move servo 2",0,180,90,7){}
void run(){
menuSystemOverTty.msgPause(dummyMessage);
}
bool refresh(){
if(menuOptionRangeValue::refresh()){// have the value changed?
myServo2.write(state);
return true;
}
return false;
}
};
testOption1 firstMenuItem = testOption1();
testOption3 ThirdMenuItem = testOption3();
testOption4 fourthMenuItem = testOption4();
testUiStuff secondMenuItem = testUiStuff();
screenMenu utilitats = screenMenu("Arduino Menu System demo2");
void motionDetectStateChange(){
motionDetectStatus = digitalRead(motionDetectPin);
}
void setup() {
Serial.begin(9600);
while (!Serial) {;}
myServo1.attach(servo1Pin);
myServo2.attach(servo2Pin);
pinMode(motionDetectPin, INPUT);
attachInterrupt(digitalPinToInterrupt(motionDetectPin), motionDetectStateChange, CHANGE);
menuSystemOverTty.addscreen(&utilitats);
utilitats.addMenuOption(&firstMenuItem);// the order goes here
utilitats.addMenuOption(&ThirdMenuItem);
utilitats.addMenuOption(&fourthMenuItem);
utilitats.addMenuOption(&secondMenuItem);
utilitats.autoRefresh = true;
menuSystemOverTty.init(&Serial);// requiered at boot
}
void loop() {
menuSystemOverTty.run();
}