How would I edit this code to do the following.
// What I need is:
// Pushbutton Switch with pull UP resistor for testing.(OPTOCOUPLER-NPN INPUT)
// Analog 0 is held HIGH by 10k resistor to 5V+. (switched 12v+ in the OFF state)
// When Analog 0 changes from High to LOW, OUTPUT 9 stays on for 1 second.
// Whilst Analog 0 is held LOW both OUTPUTS are OFF.(switched 12v+ in the ON state)
// When Analog 0 changes from LOW to HIGH, OUTPUT 8 stays on for 1 second.
// Whilst Analog 0 is held HIGH both OUTPUTS are OFF.(switched 12v+ in the OFF state)
// Picture of my setup http://i50.tinypic.com/2m5xte0.jpg
// Code in it’s current state:
// Pushbutton Switch with pull DOWN resistor for testing.
// Analog 0 is held LOW by 10k resistor to GND. (switched 12v+ in the OFF state)
// At start up OUTPUT 9 is OFF & OUTPUT 8 is OFF.
// Tap button & OUTPUT 9 turns ON for 1 second followed by OUTPUT 8 for 1 second.(pulse of 12v+)
// Whilst button is held OUTPUT 9 is ON & output 8 is OFF.(switched 12v+ in the ON state)
// When button is released OUTPUT 9 stays on for 1 second, then OUTPUT 8 turns on for 1 second.
// Thank you to Kenny From the Netherlands.
// Define what is going to be used
#define Analog_0 A0
#define Digital_8 8
#define Digital_9 9
void setup()
{
//inputs and outputs
pinMode(Analog_0, INPUT);
pinMode(Digital_8, OUTPUT);
pinMode(Digital_9, OUTPUT);
}
//Use this so the switching can only happen once every switching state
boolean Dig_8_Allowed;
boolean Dig_9_Allowed;
void loop()
{
if (digitalRead(Analog_0) == LOW)
{
Dig_9_Allowed = true;
if (Dig_8_Allowed == true)
{
Dig_8_Allowed = false;
digitalWrite(Digital_8, HIGH);
delay(1000);
digitalWrite(Digital_8, LOW);
}
}
if (digitalRead(Analog_0) == HIGH)
{
Dig_8_Allowed = true;
if (Dig_9_Allowed == true)
{
digitalWrite(Digital_9, HIGH);
delay(1000);
digitalWrite(Digital_9, LOW);
}
}
}