-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEScooter_Blinker.ino
203 lines (154 loc) · 4.15 KB
/
EScooter_Blinker.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include <Adafruit_NeoPixel.h>
#include <LiquidCrystal_I2C.h>
#include <ezButton.h>
#include <ESP32Time.h>
#include <TinyGPSPlus.h>
ESP32Time rtc(3600);
String uhr = "0";
TinyGPSPlus gps;
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define PIN_NEO_PIXEL 15
#define NUM_PIXELS 22
#define BUTTON_PIN_R 19
#define BUTTON_PIN_L 18
int Year = gps.date.year();
byte Month = gps.date.month();
byte Day = gps.date.day();
byte Hour = gps.time.hour();
byte Minute = gps.time.minute();
byte Second = gps.time.second();
ezButton button_l(BUTTON_PIN_L);
ezButton button_r(BUTTON_PIN_R);
int a = 1;
int startupvar = 1;
Adafruit_NeoPixel NeoPixel(NUM_PIXELS, PIN_NEO_PIXEL, NEO_GRB + NEO_KHZ800);
void blinker_l() {
for (int i=0; i<2; i++) {
NeoPixel.fill(NeoPixel.Color(0, 0, 0), 0, 9);
Serial.println(i);
for (int pixel = 9; pixel>-1; pixel--) {
NeoPixel.setPixelColor(pixel, NeoPixel.Color(255, 255, 0));
NeoPixel.show();
delay(70);
}
// if(digitalRead(button_r.isPressed())) {
// i = 3;
// }
}
NeoPixel.fill(NeoPixel.Color(209/5, 134/5, 0), 0, 6);
NeoPixel.fill(NeoPixel.Color(255, 0, 0), 6, 4);
NeoPixel.show();
}
void blinker_r() {
for (int i=0; i<2; i++) {
NeoPixel.fill(NeoPixel.Color(0, 0, 0), 12, 10);
for (int pixel = 12; pixel < 22; pixel++) {
NeoPixel.setPixelColor(pixel, NeoPixel.Color(255, 255, 0));
NeoPixel.show();
delay(70);
}
//currentState_R = digitalRead(BUTTON_PIN_R);
// if(lastState_R == HIGH && currentState_R == LOW) {
// i = 3;
// }
}
NeoPixel.fill(NeoPixel.Color(209/5, 134/5, 0), 16, 6);
NeoPixel.fill(NeoPixel.Color(255, 0, 0), 12, 4);
NeoPixel.show();
}
void gettime() {
// setTime(Hour, Minute, Second, Day, Month, Year);
rtc.setTime(Second, Minute, Hour, Day, Month, Year);
// adjusttime(2, 0);
}
void emergency() {
NeoPixel.fill(NeoPixel.Color(255, 255, 0), 0, NUM_PIXELS);
NeoPixel.show();
delay(200);
NeoPixel.fill(NeoPixel.Color(0, 0, 0), 0, NUM_PIXELS);
NeoPixel.show();
delay(200);
}
void startup(){
for (int pixel = 0; pixel < 6; pixel++) {
NeoPixel.setPixelColor(pixel, NeoPixel.Color(209/5, 134/5, 0));
NeoPixel.show();
delay(70);
}
for (int pixel = 6; pixel < 16; pixel++) {
NeoPixel.setPixelColor(pixel, NeoPixel.Color(255, 0, 0));
NeoPixel.show();
delay(70);
}
for (int pixel = 16; pixel < 22; pixel++) {
NeoPixel.setPixelColor(pixel, NeoPixel.Color(209/5, 134/5, 0));
NeoPixel.show();
delay(70);
}
}
void setup() {
Serial.begin(9600);
Serial2.begin(9600);
NeoPixel.begin();
button_l.setDebounceTime(100);
button_r.setDebounceTime(100);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Enabled.");
startup();
}
void loop() {
button_l.loop();
button_r.loop();
if(button_l.getState() == 0 && button_r.getState() == 1) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Blinker links");
Serial.println("Blinker links");
blinker_l();
lcd.clear();
} else if (button_r.getState() == 0 && button_l.getState() == 1) {
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("Blinker rechts");
Serial.println("Blinker rechts");
blinker_r();
lcd.clear();
}
// Serial.write(Serial2.read());
if (gps.encode(Serial2.read())){
/*
if (gps.time.isUpdated()) {
byte Hour = gps.time.hour();
byte Minute = gps.time.minute();
byte Second = gps.time.second();
int HourMESZ = Hour + 2;
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(HourMESZ);
lcd.print(":");
lcd.print(Minute);
lcd.print(":");
lcd.print(Second);
lcd.setCursor(0, 0);
lcd.print("Speed: ");
lcd.print(gps.speed.kmph());
}
} */
if (gps.time.isValid() && startupvar == 1){
gettime();
startupvar = 0;
} else {
lcd.setCursor(0, 1);
lcd.print("No GPS");
}
}
if (rtc.getTime() != uhr) {
lcd.setCursor(0, 1);
lcd.print(rtc.getTime() + "\n");
Serial.println(rtc.getDateTime(true) + "\n");
Serial.println(gps.time.hour() + "\n");
String uhr = rtc.getTime();
}
}