-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolenoid_cloches.ino
168 lines (163 loc) · 3.95 KB
/
solenoid_cloches.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <Button.h>
Button btn1(2);
Button btn2(3);
Button btn3(4);
Button btn4(5);
unsigned long currentMillis, prevMillis;
boolean routine = true;
//--------------------------
// MENU SET
const int NBMENU = 6;
int pulsePrecision = 20; //menu 1
int pulseIntervalCourt = 33; //menu 2
int pulseIntervalLong = 99; //menu 3
int pulseNumber = 5; //menu 4
int waveDelay = 1500; //menu5
String shem = "01001"; //menu 6
int shemIndex = 0;
int menu = 0;
int val = 0;
void setup() {
btn1.begin();
btn2.begin();
btn3.begin();
btn4.begin();
while (!Serial) { }; // for Leos
Serial.begin(9600);
}
//=================================
// FUNCTIONS
void Dong(int interval) {
Serial.print("HIGH -- ");
delay(pulsePrecision);
Serial.println("LOW");
delay(interval);
}
void Routine() {
for (int i = 0; i < pulseNumber ; i++) {
Serial.print(i);
if (shem.charAt(i) == '0') {
Serial.print(" |court| ");
Dong(pulseIntervalCourt);
} else {
Serial.print(" |long| ");
Dong(pulseIntervalLong);
}
}
Serial.println();
}
//=================================
// L00P
void loop() {
//---------------------------
// TRIGGER MENU | ->(DANS LE MENU) | ROUTINE
if (btn3.pressed()) {
routine = false;
menu++;
if (menu > NBMENU) {
menu = 1;
} else if (menu < 1) {
menu = NBMENU;
}
} else if (btn4.pressed()) {
routine = true;
Serial.println("GOOOO");
}
//---------------------------
// DANS LA ROUTINE
if (routine) {
currentMillis = millis();
if (currentMillis - prevMillis >= waveDelay) {
prevMillis = currentMillis;
Routine();
}
}
//---------------------------
// DANS LE MENU
else {
switch (menu) {
case 1:
if (btn1.pressed()) {
pulsePrecision --;
delay(2);
} else if (btn2.pressed()) {
pulsePrecision ++;
delay(2);
}
Serial.print("Pulse Precision : ");
Serial.println(pulsePrecision);
break;
case 2:
if (btn1.pressed()) {
pulseIntervalCourt --;
delay(2);
} else if (btn2.pressed()) {
pulseIntervalCourt ++;
delay(2);
}
Serial.print("Pulse Interval Court: ");
Serial.println(pulseIntervalCourt);
break;
case 3:
if (btn1.pressed()) {
currentMillis = millis();
if(currentMillis-prevMillis>=200){
while(btn1.pressed()){
pulseIntervalLong--;
}
}
pulseIntervalLong --;
delay(2);
} else if (btn2.pressed()) {
pulseIntervalLong ++;
delay(2);
}
Serial.print("Pulse Interval Long : ");
Serial.println(pulseIntervalLong);
break;
case 4:
if (btn1.pressed()) {
pulseNumber --;
shem.remove(pulseNumber + 1);
delay(2);
} else if (btn2.pressed()) {
pulseNumber ++;
shem += String(random(0, 1));
delay(2);
}
Serial.print("Nombre de pulsation : ");
Serial.println(pulseNumber);
break;
case 5:
if (btn1.pressed()) {
waveDelay --;
delay(2);
} else if (btn2.pressed()) {
waveDelay ++;
delay(2);
}
Serial.print("Waves delay : ");
Serial.println(waveDelay / 1000);
break;
case 6:
Serial.print("shemIndex ");
Serial.print(shemIndex);
Serial.print(" : ");
Serial.println(shem.charAt(shemIndex));
if (btn1.pressed()) {
shem.setCharAt(shemIndex, '0');
delay(2);
} else if (btn2.pressed()) {
shem.setCharAt(shemIndex, '1');
delay(2);
} else if (btn3.pressed()) {
shemIndex ++;
if (shemIndex > shem.length()-1) {
menu = 1;
shemIndex = 0;
}
}
break;
}
}
}