Hi guys very new to the world of Arduino and have had a lot of help from this forum regarding my project.
I'm happy my project is now working but having trouble hooking it up to a relay board. when i do the lights on the board are opposite to what i want it to do.
I think i need to pull the pins LOW but am unsure what code or where to put it. Please don't roast me I'm still learning and any help would be appreciated.
// Pin 13 onboard red LED
// Pin 9 onboard green LED
// Pin 2 button/switch.
// Pin 4 Air solenoid
unsigned long airStart, flashStart; // timers
const unsigned long airInterval = 330000, // 5 minutes + 30 secs
flashInterval = 300;
const int airEnd = 30000, // 10 seconds
flashEnd = 100; // red ON time
bool oldButton = true;
byte counter; // flash counter
int red = 13;
int green = 9;
int button = 2;
int Air = 4;
////////////////////////////////////////////////////
void setup() {
// initialize the digital pin as an output.
pinMode(red,OUTPUT);
pinMode(green,OUTPUT);
pinMode(button, INPUT_PULLUP);
pinMode(Air, OUTPUT);
}
void loop()
{
digitalWrite(Air,millis() - airStart < airEnd);
if(millis() - airStart > airInterval)
airStart += airInterval; // reset Air timer
digitalWrite(green,oldButton);
if(digitalRead(button) == LOW && oldButton == true){
oldButton = false;
flashStart = millis();
}
if(oldButton == false){
digitalWrite(red,millis() - flashStart < flashEnd);
if(millis() - flashStart > flashInterval){
flashStart += flashInterval; // reset flash timer
if(++counter >= 3 ){ // number of flashes
counter = 0; // reset flash counter
oldButton = true;
}
}
}
}