Skip to content

Instantly share code, notes, and snippets.

@skarcha
Created November 30, 2011 00:18
Show Gist options
  • Save skarcha/1407304 to your computer and use it in GitHub Desktop.
Save skarcha/1407304 to your computer and use it in GitHub Desktop.
Using LCD with Arduino
/*
Show analog input value using a LCD.
Turn on and off the backlight with a button.
By Antonio Perez <[email protected]>
Public Domain
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int analogInPin = A0;
const int lightPin = 10;
const int buttonPin = 9;
int sensorValue = 0;
int buttonState = 0;
int lastButtonState = 0;
int powerLight = LOW;
void setup() {
pinMode(lightPin, OUTPUT);
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("Resistor value:");
}
void loop() {
sensorValue = analogRead (analogInPin);
buttonState = digitalRead (buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
powerLight = !powerLight;
digitalWrite (lightPin, powerLight);
}
lastButtonState = buttonState;
}
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(sensorValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment