Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int ledPin1 = 12;
- const int ledPin2 = 11;
- const int ledPin3 = 4;
- int count = 0;
- int buttonState = 0;
- bool lastButtonState;
- const int buttonPin = 2;
- unsigned long previousMillis = 0;
- const unsigned long interval = 50;
- void setup() {
- pinMode(ledPin1, OUTPUT);
- pinMode(ledPin2, OUTPUT);
- pinMode(buttonPin, INPUT);
- pinMode (ledPin3, OUTPUT) ;
- }
- void loop() {
- unsigned long currentMillis = millis();
- buttonState = digitalRead(buttonPin);
- if (buttonState == HIGH && lastButtonState == LOW) {
- lastButtonState = buttonState;
- count++;
- }
- else {
- lastButtonState = buttonState;
- digitalWrite(ledPin3, LOW);
- digitalWrite(ledPin1, LOW);
- digitalWrite(ledPin2, LOW);
- }
- if (count == 0) {
- digitalWrite(ledPin1, HIGH);
- digitalWrite(ledPin3, HIGH);
- if (currentMillis - previousMillis >= interval) {
- digitalWrite(ledPin3, LOW);
- previousMillis = currentMillis;
- }
- }
- if (count == 1) {
- digitalWrite(ledPin2, HIGH);
- digitalWrite(ledPin3, HIGH);
- if (currentMillis - previousMillis >= interval) {
- digitalWrite(ledPin3, LOW);
- previousMillis = currentMillis;
- }
- }
- if (count == 2) {
- (count = 0);
- }
- else {
- digitalWrite(ledPin1, LOW);
- digitalWrite(ledPin2, LOW);
- digitalWrite(ledPin3, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement