void setup() {
// put your setup code here, to run once:
pinMode(switch15Output, OUTPUT);
pinMode(switch41Output, OUTPUT);
pinMode(switch15Input, INPUT);
pinMode(switch41Input, INPUT);
pinMode(redLED, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(redLED, HIGH);
delay(val);
digitalWrite(redLED, LOW);
delay(val);
while (switch15Input == HIGH && switch41Input == HIGH){
val = 100;
}
while (switch15Input == HIGH || switch41Input == HIGH){
val = 2000;
}
}
Okay, I used two pins because I thought that you needed an output to provide voltage and an input to see if the switch is pressed? Could you please explain why this is not the case?
The while statements are slightly different. One looks for switch 15 and 41 being pressed and sets the delay value to 100, the other looks for just one and assigns a 2000 delay.
Leaving your input pin floating (i.e. no connection whatsoever) is a recipe for disaster as you don't know the state of the pin (it will likely randomly fluctuate between HIGH and LOW). You must always have it pulled one way, so the switch can pull it the other way.
Easiest switch connection: one pin for input, internal pull up resistor activated, switch between the pin and GND. Reading is HIGH when the switch is open (due to the pull up resistor), LOW when the button is pressed (connecting the pin to GND - and you have a small current of <0.5 mA running through it).