i am slowly working on a code to blink leds for my rc car. so far i have the switch working the lights, and the lights blinking. i copied the code to run two relays and only relay4 is controlled buy the switch. I am extremely new to arduino.
//
const int switchPin = 8;
const int ledRelay4 = 4;
const int ledRelay3 = 5;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn4 = false;
boolean ledOn3 = false;
//
int ledState = LOW; //
//
//
unsigned long previousMillis = 0; //
//
const long interval =625 ; //
void setup() {
//
pinMode(switchPin, INPUT);
pinMode(ledRelay4, OUTPUT);
pinMode(ledRelay3, OUTPUT);
}
boolean debounce(boolean last)
{
boolean current = digitalRead(switchPin);
if (last != current)
{
delay(5);
current = digitalRead(switchPin);
}
return current;
}
void loop()
{
currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton == HIGH)
{
ledOn4 = !ledOn4;
ledOn3 = !ledOn3;
}
lastButton = currentButton;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
//
previousMillis = currentMillis;
//
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
//
if (ledOn4 && ledOn3);
digitalWrite(ledRelay4, ledState);
digitalWrite(ledRelay3, ledState);
}
}
