Created
November 30, 2011 00:18
-
-
Save skarcha/1407304 to your computer and use it in GitHub Desktop.
Revisions
-
skarcha created this gist
Nov 30, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ /* Show analog input value using a LCD. Turn on and off the backlight with a button. By Antonio Perez <aperez@skarcha.com> 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); }