Advertisement
octo_cat

Untitled

Jun 14th, 2020
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1.  
  2. const int ledPin1 =  12;
  3. const int ledPin2 =  11;
  4. const int ledPin3 = 4;
  5. int count = 0;
  6. int buttonState = 0;
  7. bool lastButtonState;
  8. const int buttonPin = 2;
  9. unsigned long previousMillis = 0;
  10. const unsigned long interval = 50;
  11.  
  12. void setup() {
  13.   pinMode(ledPin1, OUTPUT);
  14.   pinMode(ledPin2, OUTPUT);
  15.   pinMode(buttonPin, INPUT);
  16.   pinMode (ledPin3, OUTPUT) ;
  17. }
  18.  
  19. void loop() {
  20.   unsigned long currentMillis = millis();
  21.  
  22.   buttonState = digitalRead(buttonPin);
  23.   if (buttonState == HIGH && lastButtonState == LOW) {
  24.     lastButtonState = buttonState;
  25.     count++;
  26.  
  27.   }
  28.   else {
  29.     lastButtonState = buttonState;
  30.     digitalWrite(ledPin3, LOW);
  31.     digitalWrite(ledPin1, LOW);
  32.     digitalWrite(ledPin2, LOW);
  33.   }
  34.  
  35.   if (count == 0) {
  36.     digitalWrite(ledPin1, HIGH);
  37.     digitalWrite(ledPin3, HIGH);
  38.  
  39.     if (currentMillis - previousMillis >= interval) {
  40.       digitalWrite(ledPin3, LOW);
  41.       previousMillis = currentMillis;
  42.     }
  43.   }
  44.  
  45.   if (count == 1) {
  46.     digitalWrite(ledPin2, HIGH);
  47.         digitalWrite(ledPin3, HIGH);
  48.  
  49.     if (currentMillis - previousMillis >= interval) {
  50.       digitalWrite(ledPin3, LOW);
  51.       previousMillis = currentMillis;
  52.     }  
  53.   }
  54.  
  55.  
  56.   if (count == 2) {
  57.     (count = 0);
  58.   }
  59.  
  60.   else {
  61.     digitalWrite(ledPin1, LOW);
  62.     digitalWrite(ledPin2, LOW);
  63.     digitalWrite(ledPin3, LOW);
  64.   }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement