Hello, I am currently trying to write a code utilizing a N.O. pushbutton as a "trigger" to write a digital pin to high. I have a selector switch one going to pin 8,7 on my arduino. I am wanting the arduino to read which pin is "HIGH" (5V) and digitalWrite pin 4 "HIGH" for 15 seconds if pin 7 is high, and 30 is pin 8 is high. I am not a programmer by trade and am needing some help with this code.
int SecPin30 = 8; //Digital 8
int SecPin15 = 7; //Digital 7
int OutputPin = 4; //Digital 4
int val30 = 0;
int val15 = 0;
// the loop function runs over and over again forever
void loop()
{
{ if (val15==HIGH);
pinMode(OutputPin,HIGH);
delay(15000);
}
{ if (val30=HIGH);
pinMode(OutputPin,HIGH);
delay(30000);
}
What is Your problem? What help do You need? What's Your question?
Tip:
Use inputs declared as "INPUT_PULLUP" to Your buttons and the other end of the buttons connected to GND.
I am wondering if this code will perform as described, I am not able to run the code in person until tomorrow. Im am trying to work out any bugs/coding errors now.
Run Your code. That is the ultimate confirmation whether it's functioning or not. It takes a lot more time for us to "verify" that code the theoretical way.
You must check the buttons inside loop(). Setup is only executed once, at start up, pwr up, etc. pinMode(OutputPin,HIGH);
is a declaration that doesn't set any output. Use digital.write to set outputs.
You switch the pin HIGH, wait 30 seconds, switch it off and immediately loop round again. If pin 30 is still HIGH it will immediately switch on again. Same for the other pin. And if you don't have pull-down resistors on those pins then they may randomly read as HIGH at any time.
So posting a schematic showing how things are wired may give you the answer.