Hello
Big NOOB here, been working on my first project and I have found my self continuously looking online for help but this particular time I cant seem to find what I need or even know how to start it.
I have my 3 s electable Modes (with every Click) but what I want now is the activate a 5 to 30 Second Timer to CASE LINE 2 (Mode 2) once it has finished its timer I then want it to switch to a another mode automatically.
I do not want to use Delays... Delays give me no control (I want to be able to bypass the Timer ) if I was to click my manual button again.
any help (be nice) would be appreciated.
Thanks
#include <Event.h>
#include <Timer.h>
#include <Bounce2.h>
#define BUTTON_PIN_1 8
Timer t;
byte switchVal = 0;
byte prevSwitch = 0;
byte counter = 0;
const int BUTTON_PIN = 8; //Manual Button + Relay Driven RF Reciever
const byte LEDSTOP = 13; //Mode Confirm (STATUS and CONFIRM that NO RELAYS ARE ACTIVE
const byte RELAYOPEN = 7; //RELAY 1 = OPEN Gate
const byte RELAYCLOSE = 6; //RELAY 2 = CLOSE Gate
Bounce debouncer = Bounce(); //debounce library installed for mechanical switches
//in the code
void setup()
{
pinMode(BUTTON_PIN,INPUT_PULLUP); //Internal Pullup used for pushbutton to switch between modes
debouncer.attach(BUTTON_PIN); // Debounce Library (attatched for reading value for accruate response
debouncer.interval(5); // used 5ms this was standard when i set it up and it seemed to work very well
Serial.begin(9600); //used Serial to Diagnose what output is selected as quickly as possible, just incase I had interefence issues.
pinMode (BUTTON_PIN, INPUT_PULLUP);
pinMode (LEDSTOP, OUTPUT ); //Gate Stop (NOT MOVING) Possition
pinMode (RELAYOPEN, OUTPUT); //Gate Openening Possition
pinMode (RELAYCLOSE, OUTPUT); //Gate Closing Possition
}
void loop()
{
{ // Update the Bounce instance :
debouncer.update();
// Get the updated value :
int value = debouncer.read();
}
switchVal = digitalRead(BUTTON_PIN);
if ((switchVal == HIGH) && (prevSwitch == 0)) //counter used to select which case line/mode to use
{
counter ++;
prevSwitch = 1;
}
else if (switchVal == LOW)
{
prevSwitch = 0;
}
switch (counter)
{
case 1: //Case 1 (Mode 1) used to confirm Gate is in STOP POSSITION and OPEN AND CLOSE RELAYS ARE INACTIVE
digitalWrite(LEDSTOP, HIGH);
delay (100);
Serial.println("LEDSTOP");
Serial.println();
digitalWrite(RELAYOPEN, LOW);
digitalWrite(RELAYCLOSE, LOW);
break;
case 2: //Case 2 (Mode 2) used to confirm Gate is in OPEN POSSITION and CLOSE AND STOP RELAY and LAMP ARE INACTIVE
digitalWrite(RELAYOPEN, HIGH);
delay (100);
Serial.println("LEDOPEN");
Serial.println();
digitalWrite(RELAYCLOSE, LOW);
digitalWrite(LEDSTOP, LOW);
break;
case 3: //Case 3 (Mode 3) used to confirm Gate is in CLOSE POSSITION and OPEN AND STOP RELAY and LAMP ARE INACTIVE
digitalWrite(RELAYCLOSE, HIGH);
Serial.println("LEDCLOSE");
Serial.println();
digitalWrite(LEDSTOP, LOW);
digitalWrite(RELAYOPEN, LOW);
break;
default:
counter = 1; //Revert Back to Case Line 1 (MODE 1)
break;
}
}