-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloetit.ino
97 lines (79 loc) · 1.85 KB
/
loetit.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
#include <TimedAction.h>
#include <SoftwareSerial.h>
int leds[] = {3, 5, 6, 9};
boolean ledStates[] = {false, false, false, false};
int sws[] = {A5, A4, A3, A2};
int swStates[] = {LOW, LOW, LOW, LOW};
TimedAction blinkAction = TimedAction(1000, blink);
String displayText = "";
int TX = 11;
int RX = 12;
SoftwareSerial display = SoftwareSerial(12, 11); // RX, TX
int treshold = 50;
void setup(){
for (int i=0; i<4; i++){
pinMode(leds[i], OUTPUT);
pinMode(swStates[i], INPUT);
}
display.begin(9600);
// enable display
display.write(0xFE);
display.write(0x41);
delay(10);
// clear Display
display.write(0xFE);
display.write(0x51);
delay(10);
// disbale underline Cursor
display.write(0xFE);
display.write(0x48);
// disable blinking Cursor
display.write(0xFE);
display.write(0x4C);
writeText("Welcome to Simon says");
}
void loop() {
for (int i=0; i<4; i++){
swStates[i] = analogRead(sws[i]) > treshold;
if (swStates[i] == HIGH){
ledStates[i] = true;
blink();
blinkAction.reset();
}
}
blinkAction.check();
}
void blink(){
//digitalWrite(LED1, LED1_On ? HIGH : LOW);
for (int i=0; i<4; i++){
if (ledStates[i]){
//tone(leds[i], 191);
digitalWrite(leds[i], HIGH);
ledStates[i] = false;
} else {
//noTone(leds[i]);
digitalWrite(leds[i], LOW);
}
}
}
void clearText() {
//clear display
display.write(0xFE);
display.write(0x51);
delay(10);
}
void writeText(String text) {
displayText = text;
clearText();
display.print(displayText.substring(0, 16));
if (displayText.length() > 16){
// set cursor to second line
display.write(0xFE);
display.write(0x45);
display.write(0x40);
delay(10);
String secondLine = displayText.substring(16, displayText.length());
secondLine.trim();
display.print(secondLine);
}
}