So I hooked up a switch to pin 7 like so:
Then I wrote the sketch below.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
int count; //Used to keep display alive while we are reading information
void setup()
{
pinMode(7, INPUT_PULLUP); //Set pin 7 to INPUT_PULLUP, this uses the inbuilt resistor on the pin
// initialize the LCD
lcd.begin();
lcd.clear();
lcd.noBacklight();
count = 0; //Initialise the variable
}
void loop()
{
//Check to see if we have pushed a button
if (digitalRead(7) == HIGH ) {
// If the count if > 100 reset the counter and clear the screen
if (count >100){
lcd.clear();
lcd.noBacklight(); //Turn off the light
count =0;
}
else{
//If the count is not yet at 100 then display the current count
lcd.clear();
lcd.home();
lcd.print("Counting");
lcd.setCursor(0, 1); //Set to the second row
lcd.print(count);
}
} else {
//The button has been pressed
lcd.home();//Send to home
lcd.backlight(); //Turn the light on
lcd.print("Hello World"); //Print a basic message
count = 1; //Let the count begin
}
//If we have started counting then keep counting
if (count >0){
count++;
}
// Wait a short time, then we check again
delay(200);
}
BOOM!
Does the job for now, next I need to read something from USB and have that the thing being displayed.
No comments:
Post a Comment