Browse Source

Ampel für Arduino Uno R3

master
Olli Graf 1 year ago
commit
f38af95beb
  1. 62
      arduino-uno-r3/arduino-uno-r3.ino

62
arduino-uno-r3/arduino-uno-r3.ino

@ -0,0 +1,62 @@
int ledRot = 10;
int ledGelb = 11;
int ledGruen = 12;
boolean blinkmode = false;
int phase = 1;// Ampelphase
void setup() {
// put your setup code here, to run once:
pinMode(ledRot, OUTPUT);
pinMode(ledGelb, OUTPUT);
pinMode(ledGruen, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(blinkmode) {
// Blinkmodus
digitalWrite(ledRot, HIGH);
digitalWrite(ledGelb, HIGH);
digitalWrite(ledGruen, HIGH);
delay(1500);
digitalWrite(ledRot, LOW);
digitalWrite(ledGelb, LOW);
digitalWrite(ledGruen, LOW);
delay(200);
}
else {
// Ampelmodus
printf("Phase: %d", phase);
switch(phase) {
case 1: // Phase rot
digitalWrite(ledRot, HIGH);
digitalWrite(ledGelb, LOW);
digitalWrite(ledGruen, LOW);
delay(1500);
phase = 2;
break;
case 2: // Phase Rot/Gelb
digitalWrite(ledRot, HIGH);
digitalWrite(ledGelb, HIGH);
digitalWrite(ledGruen, LOW);
delay(1000);
phase = 3;
break;
case 3: // Phase Grün
digitalWrite(ledRot, LOW);
digitalWrite(ledGelb, LOW);
digitalWrite(ledGruen, HIGH);
delay(2000);
phase = 4;
break;
case 4: // Phase Gelb
digitalWrite(ledRot, LOW);
digitalWrite(ledGelb, HIGH);
digitalWrite(ledGruen, LOW);
delay(1500);
phase = 1;
break;
}
}
}
Loading…
Cancel
Save