I modeled the circuit using TinkerCad's Arduino module. This took about 1.5 hours testing different code files, playing with timings, and trying different resistors and wiring diagrams. This allowed me to similtaneously debug the circuitboard and the code seamlessly.
Tinkercad is like Canva for EE
I decided to use as many pins and lights as possible and hoped this wouldn't overload the board. Below is the finalized code used to create this effect:
Note: don't confuse 10,000 ohm with 220 ohm (see struggling LEDs 2 & 3)
const example = "Hello, world!";
console.log(example);
unsigned long previousMillis = 0;
// Delay to determine speed of scan:
unsigned long interval = 100;
// Array with Arduino pins containing LEDs in sequence
byte LEDpins[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
// Variable to track which LED to turn on
int currentLED = 0;
boolean direction = UP;
void setup() {
// Set Pins with LEDs to OUTPUT
for (int x = 0; x < 10; x++)
pinMode(LEDpins[x], OUTPUT);
}
void loop() {
digitalWrite(LEDpins[x], x == currentLED);
unsigned long currentMillis = millis();
if ((unsigned long)(currentMillis - previousMillis) >= interval) {
previousMillis = currentMillis;
if (direction == UP) {
currentLED++;
if (currentLED == 10) {
currentLED = 8; // Set to the second-to-last LED
direction = DOWN;
}
} else {
currentLED--;
if (currentLED < 0) {
currentLED = 1; // Set to the second LED
direction = UP;
}
}
}
}
}
I messed with the timings until the wave was visually appealing.
One of my classmates suggested I add a button to shoot a laserbeam down the line of LEDs, so I added this after drafting in TinkerCad. Here is the result:
Lastly, I will be using two ESP32s for my final project because I will be using radio controlled LEDs and potentially incorporate WIFI. To get a head start, I installed the Arduino ESP32 add-on and familiarized myself with the interface.