Hello,
this is my first post on the arduino forum. I'm having issues with a personal project and need some guidance, specifically about wiring.
I'm trying to increment a number on the lcd with a pushbutton. Pushing the button currently results in either incrementing correctly and the screen dimming and going blank while pushing / or the screen dimming and going blank, and not showing anything afterwards.
Either way the screen shouldn't dim and it shouldn't remove the characters while pushing. It should only increment the number when the button is pushed and released.
this is my current setup, lcd functioning: (my biggest apology in advance for the unclear wiring, I am a rookie and don't really have the good knowledge and materials for working properly yet)
I use 1 jumper from arduino 5V to the breadboard, powering the lcd and the button, ditto with the ground.
However, I feel like I wired the button wrong, causing the screen to dim/go blank and 80% of the time not incrementing and leaving the screen blank.
my code uploaded:
#include <LiquidCrystal.h> //Library LiquidCrystal
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int Up_buttonPin = 7;
int buttonPushCounter = 0; // counter for the number of button presses
int up_buttonState = 0; // current state of the up button
int up_lastButtonState = 0; // previous state of the up button
bool bPress = false;
void setup()
{
Serial.begin(9600);
pinMode( Up_buttonPin , INPUT_PULLUP);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Counter Value:");
lcd.setCursor(2, 1);
lcd.print(buttonPushCounter);
}
void loop()
{
checkUp();
if ( bPress)
{
bPress = false;
lcd.setCursor(2, 1);
lcd.print(" ");
lcd.setCursor(2, 1);
lcd.print(buttonPushCounter);
}
}
void checkUp()
{
up_buttonState = digitalRead(Up_buttonPin);
if (up_buttonState != up_lastButtonState) // compare the buttonState to its previous state
{
if (up_buttonState == LOW) // if the state has changed, increment the counter
{
bPress = true; // if the current state is HIGH then the button went from off to on:
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
}
else {
Serial.println("off"); // if the current state is LOW then the button went from on to off:
}
delay(50); // Delay a little bit to avoid bouncing
}
up_lastButtonState = up_buttonState; // save the current state as the last state, for next time through the loop
}
Thanks,
Arthur