This is probably very simple. But it's beyond my scope. i am a noob. Please help me
The code below is working for me with a dc motor and 2 channel relay. I can turn CW only
To turn CCW. I want to add another Relay pin (named pin 12) and do the same thing as pin 13 below.
And add another Button pin (named pin 3) and do the same thing as pin 2 below.
void setup()
{
pinMode(13,OUTPUT); // Relay output
pinMode(2,INPUT_PULLUP); // Button input
Serial.begin(9600);
}
void loop()
{
static unsigned char relayState = LOW;
static unsigned char buttonState = LOW;
static unsigned char lastButtonState = LOW;
static unsigned long relayCameOn = 0;
//
if(relayState == HIGH)
{
if(millis()-relayCameOn > 1000)
{
digitalWrite(13,HIGH);
relayState = LOW;
Serial.println("off");
}
}
// If the button's state has changed, then turn the LED on IF it is not on already.
buttonState = digitalRead(2);
if(buttonState != lastButtonState)
{
lastButtonState = buttonState;
if((buttonState == HIGH) && (relayState == LOW))
{
digitalWrite(13,LOW);
relayState = HIGH;
relayCameOn = millis();
Serial.println("on");
}
}
}