/**************************************************
Explanation of the Code:
Pin Setup: The 10 LEDs are connected to pins 2 through 11.
frequency Variable: Set to 2 Hz by default, meaning the
LEDs will chase 2 times per second.
interval Calculation: The interval for switching LEDs
is based on the frequency and determines how long each LED stays on.
LED Chasing Logic:
The millis() function ensures non-blocking timing for
the LED chase.
Each LED is turned on for the calculated interval and
then turns off as the next LED lights up.
The currentLed wraps around to 0 after reaching the last LED,
making the chaser continuous.
Adjusting Speed:
To change the speed of the LED chase, you can modify the frequency variable. For example:
frequency = 5; would make the chase 5 times per second (faster).
frequency = 1; would make the chase 1 time per second (slower).
https://chatgpt.com/share/c0099c09-14ba-4cf1-aa96-49c3a8fd812d
by arvind patil
**************************************************/
const int numLeds = 10; // Number of LEDs
int ledPins[numLeds] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // Pins connected to the LEDs
int currentLed = 0; // To track the current LED
unsigned long previousMillis = 0; // To store the last time an LED was updated
int frequency = 2; // Frequency in Hz (chasing frequency)
unsigned long interval = 1000 / (2 * frequency); // Calculate interval (half-period for switching)
void setup() {
// Set all LED pins as OUTPUT
for (int i = 0; i < numLeds; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
unsigned long currentMillis = millis();
// Check if it's time to move to the next LED
if (currentMillis - previousMillis >= interval) {
// Save the last time we updated the LEDs
previousMillis = currentMillis;
// Turn off all LEDs
for (int i = 0; i < numLeds; i++) {
digitalWrite(ledPins[i], LOW);
}
// Turn on the current LED
digitalWrite(ledPins[currentLed], HIGH);
// Move to the next LED, wrap around if necessary
currentLed = (currentLed + 1) % numLeds;
}
}
nano:12
nano:11
nano:10
nano:9
nano:8
nano:7
nano:6
nano:5
nano:4
nano:3
nano:2
nano:GND.2
nano:RESET.2
nano:0
nano:1
nano:13
nano:3.3V
nano:AREF
nano:A0
nano:A1
nano:A2
nano:A3
nano:A4
nano:A5
nano:A6
nano:A7
nano:5V
nano:RESET
nano:GND.1
nano:VIN
nano:12.2
nano:5V.2
nano:13.2
nano:11.2
nano:RESET.3
nano:GND.3
led1:A
led1:C
led2:A
led2:C
led3:A
led3:C
led4:A
led4:C
led5:A
led5:C
led6:A
led6:C
led7:A
led7:C
led8:A
led8:C
led9:A
led9:C
led10:A
led10:C