Jump to content

Arduino Button and LCD screen help

So I have the grove starter kit for the Arduino Uno (https://www.seeedstudio.com/Grove-Starter-Kit-for-Arduino-p-1855.html#) and have started to play around with it, but what I am trying to do now it when you click the button that comes with the starter kit it changes the text on the LCD screen that comes in the starter kit also. I have tried to get it working but I can't.

 

My Code:

#include <Wire.h>
#include "rgb_lcd.h"

rgb_lcd lcd;

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
    // initialize the pushbutton pin as an input:
    pinMode(buttonPin, INPUT);
    
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
    // Print a message to the LCD.
    lcd.print("System Enabled!");
}

void loop(){
  
}

void activate(){

  // read the state of the pushbutton value:
    buttonState = digitalRead(buttonPin);

    // check if the pushbutton is pressed.
    // if it is, the buttonState is HIGH:
    if (buttonState == HIGH) {
        lcd.print("System Disabled!");
    }
    if (buttonState == LOW) {
        lcd.print("System Enabled!");
    }  
}

Thanks!

Link to comment
Share on other sites

Link to post
Share on other sites

22 hours ago, gabrielcarvfer said:

@DerpDiamonds, seems like you didn't setup the RGB color with

 

const int colorR = 255;
const int colorG = 0;
const int colorB = 0;

lcd.setRGB(colorR, colorG, colorB);

 

after LCD begin.

 

In the loop function, looks like you need to set the cursor line and column with

 

lcd.setCursor(0, 0);

 

After that you should read if your button got activated and then print the message in case it's affirmative. You can do that by calling activate function inside the loop one. 

 

When I have done that stuff and plugged the LCD and the button in  the LCD responds, but just not with the button plugged in. What is this? Is it a bug or a problem with my arduino editor?

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×