Skip to content

Instantly share code, notes, and snippets.

@skarcha
Created November 30, 2011 00:18
Show Gist options
  • Select an option

  • Save skarcha/1407304 to your computer and use it in GitHub Desktop.

Select an option

Save skarcha/1407304 to your computer and use it in GitHub Desktop.

Revisions

  1. skarcha created this gist Nov 30, 2011.
    52 changes: 52 additions & 0 deletions gistfile1.ino
    Original 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);
    }