I have a background in electronics and Circuit design but I'm new to micro-controllers and programming on the arduino. I'm still on the basics programming projects, but what i'm trying to do is get a single "button switch" to toggle between different LEDs and execute different functions.
can anyone tell me what i am doing wrong? I've tried multiple variations with no luck.
//Button Switch Circuit w/ Button Counter
const int greenled = 6;
const int buttonPin = 9;
const int yellowled = 10;
const int redled = 11;
int lastbuttonState = LOW;
int buttonPushCounter = LOW;
int buttonState = LOW;
void setup()
{
pinMode(buttonPin, INPUT);
pinMode(redled, OUTPUT);
pinMode(yellowled, OUTPUT);
pinMode(greenled, OUTPUT);
}
void loop ()
{
buttonState = digitalRead(buttonPin);{
if (buttonState == HIGH)
{
buttonPushCounter = (buttonPushCounter++);
}
if (buttonPushCounter = 0); {
digitalWrite(redled, LOW);
digitalWrite(yellowled, LOW);
digitalWrite(greenled, LOW);
}
if (buttonPushCounter == 1) {
digitalWrite(redled, HIGH);
}
if (buttonPushCounter == 2) {
digitalWrite (yellowled, HIGH);
digitalWrite (redled, HIGH);
}
if (buttonPushCounter == 4) {
digitalWrite(greenled, HIGH);
digitalWrite(yellowled,HIGH);
}
if (buttonPushCounter == 3) {
digitalWrite (greenled, HIGH);
digitalWrite (yellowled, HIGH);
digitalWrite (redled, HIGH);
}
if (buttonPushCounter == 5) {
digitalWrite (greenled, LOW);
digitalWrite (yellowled, HIGH);
digitalWrite (redled, LOW);
}
if (buttonPushCounter == 6) {
digitalWrite (greenled, HIGH);
digitalWrite (yellowled, LOW);
digitalWrite (redled, LOW);
}
if (buttonPushCounter == 7) {
digitalWrite (greenled, HIGH);
digitalWrite (yellowled, LOW);
digitalWrite (redled, HIGH);
}
}
}
this code was my attempt to get different combinations of LEDs to come on with the same button pressed over and over... sadly with no luck