Advertisement
Guest User

Untitled

a guest
May 27th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. enum led {
  2.   VILLOG_KI,
  3.   VILLOG_BE,
  4.   LED_BE,
  5.   LED_KI
  6. };
  7.  
  8. enum led led_allapot;
  9. const int ledPin = 13;
  10. long sebesseg = 500;
  11. unsigned long ido_regi = 0;
  12.  
  13. void setup() {
  14.   pinMode(ledPin, OUTPUT);
  15.   Serial.begin(9600);
  16. }
  17.  
  18. void loop() {
  19.   unsigned long ido = millis();
  20.  
  21.   if (Serial.available() > 0) {
  22.     char kapcsolo = Serial.read();
  23.     // turn off LED
  24.     if (kapcsolo == '-')
  25.       led_allapot = VILLOG_KI;
  26.  
  27.     // turn on LED
  28.     if (kapcsolo == '+')
  29.       led_allapot = VILLOG_BE;
  30.   }
  31.  
  32.   if (led_allapot > VILLOG_KI) {
  33.     if ((unsigned long)(ido - ido_regi >= sebesseg)) {
  34.       if (led_allapot == LED_BE) {
  35.         led_allapot = LED_KI;
  36.         digitalWrite(ledPin, LOW);
  37.       } else {
  38.         led_allapot = LED_BE;
  39.         digitalWrite(ledPin, HIGH);
  40.       }
  41.       ido_regi = ido;
  42.     }
  43.   } else if (led_allapot == VILLOG_KI) {
  44.     digitalWrite(ledPin, LOW);
  45.   }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement