// SUPER ARDUINOVA (SA-12L) - Complete Implementation
// Compliant with Technical Regulations Document
// Pin Definitions
const int buttonPin = 13; // Mode selection button
const int ledPins[] = {12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, A3}; // 12 LED pins
// Global Variables
int currentMode = 1; // Start with Mode 1
int buttonState = 0; // Current button state
int lastButtonState = 0; // Previous button state
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
unsigned long previousMillis = 0;
// Mode timing constants
const long mode2Interval = 250; // 2Hz = 500ms period, 250ms on/off
const long mode1Interval = 100; // Scanner speed
const long mode3Interval = 150; // Chase speed
void setup() {
// Initialize all LED pins as outputs
for (int i = 0; i < 12; i++) {
pinMode(ledPins[i], OUTPUT);
digitalWrite(ledPins[i], LOW);
}
// Initialize button pin with pull-down resistor
pinMode(buttonPin, INPUT);
// Serial.begin(9600); // Optional: for debugging
}
void loop() {
// Handle mode selection via button
handleModeSelection();
// Execute current mode pattern
switch (currentMode) {
case 1:
mode1Sequential();
break;
case 2:
mode2Hazard();
break;
case 3:
mode3Converge();
break;
}
}
void handleModeSelection() {
// Read the button state with debouncing
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
// Only change mode on button press (not release)
if (buttonState == HIGH) {
currentMode++;
if (currentMode > 3) {
currentMode = 1;
}
// Turn off all LEDs when changing modes
allLEDsOff();
}
}
}
lastButtonState = reading;
}
// MODE 1: Sequential (Larson Scanner)
void mode1Sequential() {
static int currentLED = 0;
static bool movingForward = true;
static unsigned long previousMode1Millis = 0;
unsigned long currentMillis = millis();
if (currentMillis - previousMode1Millis >= mode1Interval) {
previousMode1Millis = currentMillis;
// Turn off all LEDs
allLEDsOff();
// Turn on current LED
digitalWrite(ledPins[currentLED], HIGH);
// Move to next position
if (movingForward) {
currentLED++;
if (currentLED >= 11) { // Changed from 12 to 11 for 0-based indexing
movingForward = false;
}
} else {
currentLED--;
if (currentLED <= 0) {
movingForward = true;
}
}
}
}
// MODE 2: Hazard (Synchronized Flash)
void mode2Hazard() {
static bool ledsOn = false;
static unsigned long previousMode2Millis = 0;
unsigned long currentMillis = millis();
if (currentMillis - previousMode2Millis >= mode2Interval) {
previousMode2Millis = currentMillis;
ledsOn = !ledsOn;
if (ledsOn) {
allLEDsOn();
} else {
allLEDsOff();
}
}
}
// MODE 3: Converge (Inward Chase)
void mode3Converge() {
static int position = 0;
static unsigned long previousMode3Millis = 0;
unsigned long currentMillis = millis();
if (currentMillis - previousMode3Millis >= mode3Interval) {
previousMode3Millis = currentMillis;
// Turn off all LEDs
allLEDsOff();
// Light up symmetric pairs
digitalWrite(ledPins[position], HIGH);
digitalWrite(ledPins[11 - position], HIGH);
// Move to next position
position++;
if (position > 5) { // 0-5 covers all 6 pairs (12 LEDs)
position = 0;
}
}
}
// Helper functions
void allLEDsOff() {
for (int i = 0; i < 12; i++) {
digitalWrite(ledPins[i], LOW);
}
}
void allLEDsOn() {
for (int i = 0; i < 12; i++) {
digitalWrite(ledPins[i], HIGH);
}
}