Devices & Components
10 jumper wires 150mm male
Arduino Uno Rev3
LED (generic)
1.2 K ohm resistor 10x
Breadboard 100x160
Software & Tools
PCBX Simulation&EDA
Project description
Code
ARDUINO_led running light
js
// Define the pins connected to the LEDs const int
1// Define the pins connected to the LEDs 2const int ledPins[] = {3, 4, 5, 6, 7, 8, 9}; 3const int ledCount = sizeof(ledPins) / sizeof(ledPins[0]); 4 5void setup() { 6 // Initialize each pin as an output 7 for (int i = 0; i < ledCount; i++) { 8 pinMode(ledPins[i], OUTPUT); 9 } 10} 11 12void loop() { 13 // Loop through and light up each LED individually 14 for (int i = 0; i < ledCount; i++) { 15 digitalWrite(ledPins[i], HIGH); // Turn on the current LED 16 delay(100); // Wait for 100 milliseconds 17 digitalWrite(ledPins[i], LOW); // Turn off the current LED 18 } 19 delay(100); // Wait for 100 milliseconds 20 21 // Turn on all LEDs simultaneously 22 for (int i = 0; i < ledCount; i++) { 23 digitalWrite(ledPins[i], HIGH); // Turn on all LEDs 24 } 25 delay(1000); // Wait for 1 second 26 27 // Turn off LEDs one by one 28 for (int i = 0; i < ledCount; i++) { 29 digitalWrite(ledPins[i], LOW); // Turn off the current LED 30 delay(100); // Wait for 100 milliseconds 31 } 32 delay(1000); // Wait for 1 second 33 34 // Each LED lights up individually 3 times, with a 500ms interval 35 for (int i = 0; i < ledCount; i++) { 36 for (int j = 0; j < 3; j++) { // Each LED lights up 3 times 37 digitalWrite(ledPins[i], HIGH); // Turn on the current LED 38 delay(300); // Wait for 300 milliseconds 39 digitalWrite(ledPins[i], LOW); // Turn off the current LED 40 delay(300); // Wait for 300 milliseconds 41 } 42 } 43 // Ensure there is a delay at the end of the loop to provide enough time before the next loop starts 44 delay(1000); // Wait for 1 second 45}
Comments
Only logged in users can leave comments