Hello Guys,
I am trying to configure first an Up and down or increment and decrement control for a display to show a "Volume" increasing by one or decreasing by one....I have attached my schematic and code...I can get the "Up" count working but then I tried some "--" in my code and it didn't work..Please help....
Here is my code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12);
const int buttonPin = 5; // the pin that the Up pushbutton is attached to
const int buttonPin1 = 6; // the pin that the Down pushbutton is attached to
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
pinMode(buttonPin1, INPUT);
lcd.begin(16,2);
lcd.setCursor(0,1);
lcd.print("Volume:");
}
void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH)
{
buttonPushCounter++;
lcd.setCursor(7,1);
lcd.print(buttonPushCounter);
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
}
schematic attached