I`m trying to create a random number generator that displays the number on an LCD screen when a button is pressed having probolems (Arduino Uno)

Viewed 25

I am trying to make a random number generator that when a button is pressed will display a random number on a 16x2 LCD screen. Still, the button output goes from equaling High to Low continuously even when the button is not being pressed i do not know why the LCD screen is dark all the time even when the button is pressed.

I do not know why the LCD screen is dark all the time even when the button is pressed the small light on the Uno board flashes with the screen so I think the problem might be from the button but I do not know.

the code I'm using might be wrong as I'm new to using Lcd screens

#include <Adafruit_LiquidCrystal.h>
long randNumber;
int seconds = 0;
int buttonState = 2;
const int ledPin = 13;

Adafruit_LiquidCrystal lcd_1(0);

void setup()
{
  pinMode(buttonState,INPUT);
  pinMode(ledPin,OUTPUT);
  lcd_1.begin(16, 2);
  lcd_1.print("hello world");
   randomSeed(analogRead(0));
  buttonState = digitalRead(buttonState);
}

void loop()
{
  delay(500);
  buttonState = digitalRead(buttonState);
  digitalWrite(ledPin, !digitalRead(buttonState));
  delay(250);
  if (buttonState == HIGH){
    randNumber = random(0,9 + 1);
    lcd_1.setCursor(0, 1);
    lcd_1.print(randNumber);
    lcd_1.setCursor(4, 1);
    lcd_1.print(buttonState);
    delay(500);
     }
  else {
      lcd_1.setBacklight(0);
      lcd_1.setCursor(0, 1);
      lcd_1.print(buttonState);
      delay(500);
    }
}
`````
0 Answers
Related