Advertisement
aschuma

Lasse :: Arduino :: Ampel :: 2

Dec 10th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.20 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.print("SCHRANKE RUNTER");  
  45.     for (pos = 90; pos >= 0; pos -= 1)
  46.     {
  47.         myservo.write(pos);
  48.         delay(15);
  49.     }
  50. }
  51.  
  52. void schrankeHoch()
  53. {
  54.     Serial.print("SCHRANKE HOCH");
  55.     for (pos = 0; pos <= 90; 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("STATUS");
  94.     Serial.println(String(digitalRead(taster)));
  95.  
  96.     // AUTO AMPEL: ROT
  97.     // FUSS AMPEL: ROT
  98.     digitalWrite(pin_rot, HIGH);
  99.     digitalWrite(pin_gelb, LOW);
  100.     digitalWrite(pin_gruen, LOW);
  101.  
  102.     digitalWrite(pin_fuss_rot, HIGH);
  103.     digitalWrite(pin_fuss_gruen, LOW);
  104.  
  105.     delay(1000);
  106.  
  107.     // AUTO AMPEL: ROT
  108.     // FUSS AMPEL: ROT
  109.     digitalWrite(pin_rot, HIGH);
  110.     digitalWrite(pin_gelb, LOW);
  111.     digitalWrite(pin_gruen, LOW);
  112.  
  113.     digitalWrite(pin_fuss_rot, HIGH);
  114.     digitalWrite(pin_fuss_gruen, LOW);
  115.  
  116.     delay(1000);
  117.  
  118.     schrankeHoch();
  119.  
  120.     delay(1000);
  121.  
  122.     // AUTO AMPEL: ROT GELB
  123.     // FUSS AMPEL: ROT
  124.     digitalWrite(pin_rot, HIGH);
  125.     digitalWrite(pin_gelb, HIGH);
  126.     digitalWrite(pin_gruen, LOW);
  127.  
  128.     digitalWrite(pin_fuss_rot, HIGH);
  129.     digitalWrite(pin_fuss_gruen, LOW);
  130.  
  131.     delay(1000);
  132.  
  133.     // AUTO AMPEL: GUREN
  134.     // FUSS AMPEL: ROT
  135.     digitalWrite(pin_rot, LOW);
  136.     digitalWrite(pin_gelb, LOW);
  137.     digitalWrite(pin_gruen, HIGH);
  138.  
  139.     digitalWrite(pin_fuss_rot, HIGH);
  140.     digitalWrite(pin_fuss_gruen, LOW);
  141.  
  142.     while (tasterStatus == 0)
  143.     {
  144.         Serial.print("WARTE AUF ANFORDERUNG");
  145.         Serial.println(String(digitalRead(taster)));
  146.         delay(500);
  147.     }
  148.  
  149.     delay(2000);
  150.  
  151.     // AUTO AMPEL: GELB
  152.     // FUSS AMPEL: ROT
  153.     digitalWrite(pin_rot, LOW);
  154.     digitalWrite(pin_gelb, HIGH);
  155.     digitalWrite(pin_gruen, LOW);
  156.  
  157.     digitalWrite(pin_fuss_rot, HIGH);
  158.     digitalWrite(pin_fuss_gruen, LOW);
  159.  
  160.     delay(1000);
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement