I made the suggested changes and loaded the sketch and used some LEDs on my breadboard and have some success. The LEDs do blink in 2 second intervals but they blink without input on pin 4. How should I remedy this? I believe I am getting close. Once this piece of code it working properly I can repeat it for the other 3 sections and then I will just have to possibly use switchcase? to allow me to monitor the 4 inputs for change of state. Here is the revised code, what am I missing?
const int LEFT813 = 5; // the number of the LED pin
const int LEFT9 = 6;
const int LEFT4 = 9;
const int LEFT513 = 10;
const int SWITCHL = 4;int val= 0;
int ledState = 0; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updatedlong interval = 2000; // interval at which to blink (milliseconds)
void setup() {
// set the digital pin as output:
pinMode(LEFT813, OUTPUT);
pinMode (LEFT9, OUTPUT);
pinMode (LEFT4, OUTPUT);
pinMode (LEFT513, OUTPUT);
pinMode(SWITCHL, INPUT);
}void loop()
{
digitalRead(SWITCHL);unsigned long currentMillis = millis();
if (millis() - previousMillis >= interval)
{
previousMillis += interval;// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;// set the LED with the ledState of the variable:
digitalWrite(LEFT813, ledState);
digitalWrite(LEFT9, ledState);
digitalWrite(LEFT4, ledState);
digitalWrite(LEFT513, ledState);
}
}