const int switchPin = 8; unsigned long previousTime = 0; int switchState = 0; int prevSwitchState = 0; int led = 2; long interval = 3000; void setup() { for(int x = 2;x<8;x++){ pinMode(x, OUTPUT); } pinMode(switchPin, INPUT); } void loop() { unsigned long currentTime = millis(); if(currentTime - previousTime > interval){ previousTime = currentTime; digitalWrite(led, HIGH); led++; if(led == 7){ } } switchState = digitalRead(switchPin); if(switchState != prevSwitchState){ for(int x = 2;x<8;x++){ digitalWrite(x, LOW); } led = 2; previousTime = currentTime; } prevSwitchState = switchState; }
Learn More :
Example
- C Program String - Alphabet Count Example
- C Program Array Example: Average
- C Program Array Example: Reverse
- C Program Switch - Case Example
- C Program if - else if - else Example
- C Program Friend & Operator: Point2D Example
- C Program Friend & Operator: Vector Example
- C Program Recursion Example
- C Program Structure Example-2
- C Program Structure Example
- C Program Pointer Example
- C Program Function Example
- C Program String Example
- C Program Character Example
- C Program sizeof & memcpy Example
- C Program Array Example
- C Program Side Length Example
- C Program Pipes()
- C Program 0-1000 to Ordinary
- C Program Roboturtle
- C Program to Destroys a Mailbox
- C Program to Destroys a semaphore
- C Code for Testing the pH Meter V1.0
- APA 102c test program
- How To Retarget the C Library printf function to the UART.