const int relayPins[] = {2, 4, 16, 5, 18, 19, 21, 22, 23}; // Update with actual pin numbers
bool hasRun = false; // Flag to track execution
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Joystick Lights v1.0");
randomSeed(analogRead(0)); // Seed the random number generator
for (int i = 0; i < 9; i++) {
pinMode(relayPins[i], OUTPUT);
digitalWrite(relayPins[i], LOW); // Ensure all relays start off
}
}
void loop() {
// Run Once to Test Lights
if (!hasRun) { // Run only if hasRun is false
sequenceRelays();
hasRun = true; // Set flag to true after execution
}
// Randomly Turn on and off a light
Serial.println("Run Light Test");
randomRelay();
}
// Sequence Light Test
void sequenceRelays() {
for (int i = 0; i < 9; i++) {
digitalWrite(relayPins[i], HIGH); // Turn on relay
delay(500); // Keep it on for 500ms
digitalWrite(relayPins[i], LOW); // Turn off relay
}
}
// Random Light
void randomRelay() {
int relayIndex = random(0, 9); // Select a random relay from 0 to 8
digitalWrite(relayPins[relayIndex], HIGH);
Serial.print("Light ");
Serial.print(relayIndex);
Serial.println(" On");
delay(500);
digitalWrite(relayPins[relayIndex], LOW);
Serial.print("Light ");
Serial.print(relayIndex);
Serial.println(" OFF");
}
// How about a biniary Timer for multiple Lights? 000000000 -> 111111111
// What would be the total current load of nine lights all on simultaneously?
MOSFET