Version 1.0
Blinker🤙
This commit is contained in:
parent
d4e8b6111f
commit
7f1417c913
1 changed files with 130 additions and 0 deletions
130
blinker_uebung/blinker_uebung.ino
Normal file
130
blinker_uebung/blinker_uebung.ino
Normal file
|
@ -0,0 +1,130 @@
|
|||
#include <FVS.h>
|
||||
|
||||
hw_timer_t* timer0 = NULL;
|
||||
|
||||
int blink_link[8] = { 1, 3, 7, 15, 31, 63, 127, 255 };
|
||||
int blink_rechts[8] = { 128, 192, 224, 240, 248, 252, 254, 255 };
|
||||
|
||||
int zustand = 0;
|
||||
|
||||
int wert = 0;
|
||||
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
|
||||
void setup() {
|
||||
portMode(1, OUTPUT);
|
||||
portMode(0, INPUT);
|
||||
portWrite(1, LOW);
|
||||
|
||||
attachInterrupt(digitalPinToInterrupt(34), isr_T0, FALLING);
|
||||
attachInterrupt(digitalPinToInterrupt(35), isr_T1, FALLING);
|
||||
attachInterrupt(digitalPinToInterrupt(36), isr_T2, FALLING);
|
||||
|
||||
timer0 = timerBegin(0, 80, true);
|
||||
timerAttachInterrupt(timer0, &isr_timer0, true);
|
||||
timerAlarmWrite(timer0, 200000, true);
|
||||
timerAlarmEnable(timer0);
|
||||
|
||||
Tft.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
wert = map(analogRead(39), 0, 4095, 0, 3);
|
||||
Tft.setCursorCharacter(6,1);
|
||||
Tft.print(wert);
|
||||
zustand = wert;
|
||||
|
||||
|
||||
switch (zustand) {
|
||||
case 0:
|
||||
portWrite(1, LOW);
|
||||
Tft.setCursorCharacter(1, 1);
|
||||
|
||||
Tft.print(" ");
|
||||
break;
|
||||
case 1:
|
||||
Tft.setCursorCharacter(1, 1);
|
||||
|
||||
Tft.print("Links Blinken");
|
||||
delay(200);
|
||||
Tft.setCursorCharacter(1, 1);
|
||||
Tft.print(" ");
|
||||
delay(200);
|
||||
|
||||
break;
|
||||
case 2:
|
||||
Tft.setCursorCharacter(1, 1);
|
||||
|
||||
Tft.print("Rechts Blinken");
|
||||
delay(200);
|
||||
Tft.setCursorCharacter(1, 1);
|
||||
Tft.print(" ");
|
||||
delay(200);
|
||||
|
||||
|
||||
break;
|
||||
case 3:
|
||||
Tft.setCursorCharacter(1, 1);
|
||||
|
||||
Tft.print("Warnblinker");
|
||||
portWrite(1, 255);
|
||||
delay(200);
|
||||
Tft.setCursorCharacter(1, 1);
|
||||
|
||||
Tft.print(" ");
|
||||
portWrite(1, 0);
|
||||
delay(200);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void isr_T0() {
|
||||
if (!(zustand == 2)) {
|
||||
if (zustand != 1) {
|
||||
zustand = 1;
|
||||
} else {
|
||||
zustand = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void isr_T1() {
|
||||
if (!(zustand == 1)) {
|
||||
if (zustand != 2) {
|
||||
zustand = 2;
|
||||
} else {
|
||||
zustand = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void isr_T2() {
|
||||
if (zustand != 3) {
|
||||
zustand = 3;
|
||||
} else {
|
||||
zustand = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void isr_timer0() {
|
||||
if (zustand == 1) {
|
||||
portWrite(1, blink_link[a]);
|
||||
if (a < 7) {
|
||||
a++;
|
||||
} else {
|
||||
a = 0;
|
||||
}
|
||||
}
|
||||
if (zustand == 2) {
|
||||
portWrite(1, blink_rechts[b]);
|
||||
if (b < 7) {
|
||||
b++;
|
||||
} else {
|
||||
b = 0;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue