Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- const int pin_rot = 13;
- const int pin_gelb = 12;
- const int pin_gruen = 11;
- const int pin_fuss_rot = 10;
- const int pin_fuss_gruen = 9;
- const int taster = 3; // --> attachInterrupt = 1
- Servo myservo;
- int pos = 0;
- volatile int tasterStatus = 0;
- void setup()
- {
- Serial.begin(9600);
- myservo.attach(8);
- pinMode(pin_rot, OUTPUT);
- pinMode(pin_gelb, OUTPUT);
- pinMode(pin_gruen, OUTPUT);
- pinMode(pin_fuss_rot, OUTPUT);
- pinMode(pin_fuss_gruen, OUTPUT);
- pinMode(taster, INPUT);
- attachInterrupt(1, tasterUnterbricht, CHANGE);
- }
- void tasterUnterbricht()
- {
- if (tasterStatus == 0)
- {
- Serial.print("ANGEFORDERT");
- }
- tasterStatus = 1;
- }
- void schrankeRunter()
- {
- Serial.print("SCHRANKE RUNTER");
- for (pos = 90; pos >= 0; pos -= 1)
- {
- myservo.write(pos);
- delay(15);
- }
- }
- void schrankeHoch()
- {
- Serial.print("SCHRANKE HOCH");
- for (pos = 0; pos <= 90; pos += 1)
- {
- myservo.write(pos);
- delay(15);
- }
- }
- void loop()
- {
- // AUTO AMPEL: ROT
- // FUSS AMPEL: ROT
- digitalWrite(pin_rot, HIGH);
- digitalWrite(pin_gelb, LOW);
- digitalWrite(pin_gruen, LOW);
- digitalWrite(pin_fuss_rot, HIGH);
- digitalWrite(pin_fuss_gruen, LOW);
- delay(1000);
- // SCHRANKE
- schrankeRunter();
- delay(1000);
- // AUTO AMPEL: ROT
- // FUSS AMPEL: GRUEN
- digitalWrite(pin_rot, HIGH);
- digitalWrite(pin_gelb, LOW);
- digitalWrite(pin_gruen, LOW);
- digitalWrite(pin_fuss_rot, LOW);
- digitalWrite(pin_fuss_gruen, HIGH);
- delay(8000);
- tasterStatus = 0;
- Serial.println("STATUS");
- Serial.println(String(digitalRead(taster)));
- // AUTO AMPEL: ROT
- // FUSS AMPEL: ROT
- digitalWrite(pin_rot, HIGH);
- digitalWrite(pin_gelb, LOW);
- digitalWrite(pin_gruen, LOW);
- digitalWrite(pin_fuss_rot, HIGH);
- digitalWrite(pin_fuss_gruen, LOW);
- delay(1000);
- // AUTO AMPEL: ROT
- // FUSS AMPEL: ROT
- digitalWrite(pin_rot, HIGH);
- digitalWrite(pin_gelb, LOW);
- digitalWrite(pin_gruen, LOW);
- digitalWrite(pin_fuss_rot, HIGH);
- digitalWrite(pin_fuss_gruen, LOW);
- delay(1000);
- schrankeHoch();
- delay(1000);
- // AUTO AMPEL: ROT GELB
- // FUSS AMPEL: ROT
- digitalWrite(pin_rot, HIGH);
- digitalWrite(pin_gelb, HIGH);
- digitalWrite(pin_gruen, LOW);
- digitalWrite(pin_fuss_rot, HIGH);
- digitalWrite(pin_fuss_gruen, LOW);
- delay(1000);
- // AUTO AMPEL: GUREN
- // FUSS AMPEL: ROT
- digitalWrite(pin_rot, LOW);
- digitalWrite(pin_gelb, LOW);
- digitalWrite(pin_gruen, HIGH);
- digitalWrite(pin_fuss_rot, HIGH);
- digitalWrite(pin_fuss_gruen, LOW);
- while (tasterStatus == 0)
- {
- Serial.print("WARTE AUF ANFORDERUNG");
- Serial.println(String(digitalRead(taster)));
- delay(500);
- }
- delay(2000);
- // AUTO AMPEL: GELB
- // FUSS AMPEL: ROT
- digitalWrite(pin_rot, LOW);
- digitalWrite(pin_gelb, HIGH);
- digitalWrite(pin_gruen, LOW);
- digitalWrite(pin_fuss_rot, HIGH);
- digitalWrite(pin_fuss_gruen, LOW);
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement