aschuma

Lasse :: Arduino :: Ampel :: 3

Dec 15th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.17 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. const int pin_rot = 13;
  4. const int pin_gelb = 12;
  5. const int pin_gruen = 11;
  6.  
  7. const int pin_fuss_rot = 10;
  8. const int pin_fuss_gruen = 9;
  9.  
  10. const int taster = 3; // --> attachInterrupt = 1
  11.  
  12. Servo myservo;
  13. int pos = 0;
  14. volatile int tasterStatus = 0;
  15.  
  16. void setup()
  17. {
  18.     Serial.begin(9600);
  19.  
  20.     myservo.attach(8);
  21.  
  22.     pinMode(pin_rot, OUTPUT);
  23.     pinMode(pin_gelb, OUTPUT);
  24.     pinMode(pin_gruen, OUTPUT);
  25.     pinMode(pin_fuss_rot, OUTPUT);
  26.     pinMode(pin_fuss_gruen, OUTPUT);
  27.  
  28.     pinMode(taster, INPUT);
  29.  
  30.     attachInterrupt(1, tasterUnterbricht, CHANGE);
  31. }
  32.  
  33. void tasterUnterbricht()
  34. {
  35.     if (tasterStatus == 0)
  36.     {
  37.         Serial.print("ANGEFORDERT");
  38.     }
  39.     tasterStatus = 1;
  40. }
  41.  
  42. void schrankeRunter()
  43. {
  44.     Serial.println("SCHRANKE RUNTER");
  45.     for (pos = 0; pos <= 90; pos += 1)
  46.     {
  47.         myservo.write(pos);
  48.         delay(15);
  49.     }
  50. }
  51.  
  52. void schrankeHoch()
  53. {
  54.     Serial.println("SCHRANKE HOCH");
  55.     for (pos = 90; pos >= 0; pos -= 1)
  56.     {
  57.         myservo.write(pos);
  58.         delay(15);
  59.     }
  60. }
  61.  
  62. void loop()
  63. {
  64.     // AUTO AMPEL: ROT
  65.     // FUSS AMPEL: ROT
  66.     digitalWrite(pin_rot, HIGH);
  67.     digitalWrite(pin_gelb, LOW);
  68.     digitalWrite(pin_gruen, LOW);
  69.  
  70.     digitalWrite(pin_fuss_rot, HIGH);
  71.     digitalWrite(pin_fuss_gruen, LOW);
  72.  
  73.     delay(1000);
  74.  
  75.     // SCHRANKE
  76.     schrankeRunter();
  77.  
  78.     delay(1000);
  79.  
  80.     // AUTO AMPEL: ROT
  81.     // FUSS AMPEL: GRUEN
  82.     digitalWrite(pin_rot, HIGH);
  83.     digitalWrite(pin_gelb, LOW);
  84.     digitalWrite(pin_gruen, LOW);
  85.  
  86.     digitalWrite(pin_fuss_rot, LOW);
  87.     digitalWrite(pin_fuss_gruen, HIGH);
  88.  
  89.     delay(8000);
  90.  
  91.     tasterStatus = 0;
  92.  
  93.     Serial.println("ANGEFORDERT RUECKGESETZT");
  94.  
  95.     // AUTO AMPEL: ROT
  96.     // FUSS AMPEL: ROT
  97.     digitalWrite(pin_rot, HIGH);
  98.     digitalWrite(pin_gelb, LOW);
  99.     digitalWrite(pin_gruen, LOW);
  100.  
  101.     digitalWrite(pin_fuss_rot, HIGH);
  102.     digitalWrite(pin_fuss_gruen, LOW);
  103.  
  104.     delay(1000);
  105.  
  106.     // AUTO AMPEL: ROT
  107.     // FUSS AMPEL: ROT
  108.     digitalWrite(pin_rot, HIGH);
  109.     digitalWrite(pin_gelb, LOW);
  110.     digitalWrite(pin_gruen, LOW);
  111.  
  112.     digitalWrite(pin_fuss_rot, HIGH);
  113.     digitalWrite(pin_fuss_gruen, LOW);
  114.  
  115.     delay(1000);
  116.  
  117.     schrankeHoch();
  118.  
  119.     delay(1000);
  120.  
  121.     // AUTO AMPEL: ROT GELB
  122.     // FUSS AMPEL: ROT
  123.     digitalWrite(pin_rot, HIGH);
  124.     digitalWrite(pin_gelb, HIGH);
  125.     digitalWrite(pin_gruen, LOW);
  126.  
  127.     digitalWrite(pin_fuss_rot, HIGH);
  128.     digitalWrite(pin_fuss_gruen, LOW);
  129.  
  130.     delay(1000);
  131.  
  132.     // AUTO AMPEL: GUREN
  133.     // FUSS AMPEL: ROT
  134.     digitalWrite(pin_rot, LOW);
  135.     digitalWrite(pin_gelb, LOW);
  136.     digitalWrite(pin_gruen, HIGH);
  137.  
  138.     digitalWrite(pin_fuss_rot, HIGH);
  139.     digitalWrite(pin_fuss_gruen, LOW);
  140.  
  141.     while (tasterStatus == 0)
  142.     {
  143.         Serial.print("WARTE AUF ANFORDERUNG");
  144.         Serial.println(String(digitalRead(taster)));
  145.         delay(500);
  146.     }
  147.  
  148.     delay(2000);
  149.  
  150.     // AUTO AMPEL: GELB
  151.     // FUSS AMPEL: ROT
  152.     digitalWrite(pin_rot, LOW);
  153.     digitalWrite(pin_gelb, HIGH);
  154.     digitalWrite(pin_gruen, LOW);
  155.  
  156.     digitalWrite(pin_fuss_rot, HIGH);
  157.     digitalWrite(pin_fuss_gruen, LOW);
  158.  
  159.     delay(1000);
  160. }
Add Comment
Please, Sign In to add comment