Hello Help with a newbie here is incredibly grateful.
LED's are going to represent outputs, eventually I intend on changing to transistors to drive relays.
what do I need to do...
int pushbutton1 = 13; //Pin to send commands OPEN - STOP - CLOSE then Back to Open again...
OPEN MODE (needs a timer for 30 Seconds) (without DELAY) but I will get to this much much later.
Interrupt (if I have got this correct) I want to have the ability for the same button during a mode if selected in OPEN and CLOSE mode to PAUSE the Program. (again I expect to do this allot later on)
Pins as follows
int reading;
int LEDSTOP = 11; //Enables LEDSTOP (NO RELAYS ON) so = STOP
int LEDoPEN = 10; //Enables LEDOPEN to Turn ON RELAY 1
int LEDCLOSE = 9; //Enables LEDCLOSE to Turn ON RELAY 2
so far I have done the following (mixing and matching with code I have found online along with my own mess)
(I want to use serial so I can visually see what is going on as and when I press the button, I also have tried to implement and debounce but once again no idea what I am doing.
I am trying to learn through just editing and compiling and I clearly still do not know what I am doing... but I am really eager to learn.
please can some one look at the bellow and give me their thoughts, Hell even deconstructive criticism if you are that offended is fine as long as you follow with a constructed comment.
Many Thanks
Aaron
int counter = 0; //system starts Counter on 0
int pushbutton1 = 13; //Pin to OPEN & CLOSE
int reading;
int LEDSTOP = 11; //Enables LEDSTOP (NO RELAYS ON) so = STOP
int LEDoPEN = 10; //Enables LEDOPEN to Turn ON RELAY 1
int LEDCLOSE = 9; //Enables LEDCLOSE to Turn ON RELAY 2
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
void setup()
{
pinMode(pushbutton1, INPUT);
pinMode(LEDSTOP, OUTPUT);
pinMode(LEDoPEN, OUTPUT);
pinMode(LEDCLOSE, OUTPUT);
Serial.begin(9600);
} //Open Serial Monitor
void loop()
//Handle input
{
pushbutton1 = digitalRead(pushbutton1);
int switchVal = (digitalRead(pushbutton1) == HIGH);
if (pushbutton1 == HIGH && previous == LOW && millis() - time > debounce)
{ if (LEDSTOP == HIGH)
if (switchVal == HIGH)
}
state = LOW;
else
state = HIGH;
}
{ counter ++; //Reset count if over max mode number
if (counter == 4)
{counter = 0;}
}
else
//change mode
switch (counter) {
case 1:
digitalWrite(LEDSTOP, HIGH);Serial.println("LEDSTOP");
break;
case 2:
digitalWrite(LEDoPEN, HIGH);Serial.println("LEDOPEN");
break;
case 3:
digitalWrite(LEDCLOSE, HIGH);Serial.println("LEDCLOSE");
analogWrite(LEDCLOSE, 0);
break; }