Greetings All,
I have built a program that I want to use to turn on an LED with a momentary push button. What I want it to do is, I want the LED to come on and stay on when I push the button and then I want it to turn off and stay off when I push the button again. Since the push button is momentary, it is a little more complicated than I expected. I thought I had the program down with the one I have provided below, but the LED blinks over and over and the push button does not do anything at all. What do you recommend I do to fix this?
My Program:
//Constants
const int yellowledPin = 32; //LED Pin
const int singlePin = 38; //Push Button
boolean on=false; //For Button Switch
//Changing
int singleState = 0;
void setup() {
pinMode(yellowledPin, OUTPUT);
pinMode(singlePin, INPUT);
}
void loop() {
//adjustercheck:
singleState = digitalRead(singlePin);
if(singleState == HIGH) {
if(on == true) {
on = false;
}
else {
on = true;
}
}
if (on == true) {
digitalWrite(yellowledPin, HIGH);
}
else {
digitalWrite(yellowledPin, LOW);
}
delay(500);
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.