This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

twowordz

By: a guest on Jan 3rd, 2010  |  syntax: C  |  size: 1.31 KB  |  views: 233  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.   Takes the Analog value from a potentiometer and writes it on the screen in percentage
  3.   The circuit:
  4.   * LCD RS pin to digital pin 12
  5.   * LCD Enable pin to digital pin 11
  6.   * LCD D4 pin to digital pin 5
  7.   * LCD D5 pin to digital pin 4
  8.   * LCD D6 pin to digital pin 3
  9.   * LCD D7 pin to digital pin 2
  10.   * LCD VEE pin to ground
  11.  
  12.   * 10K resistor:
  13.   * ends to +5V and ground
  14.   * wiper to Analog pin 2  
  15. */
  16.  
  17. // use the LiquidCrystal header
  18.  #include <LiquidCrystal.h>
  19.  
  20. // initialize the library with the numbers of the interface pins
  21.  LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  22.  
  23.  
  24.  int sensorPin = 2;    // select the input pin for the potentiometer
  25.  int sensorValue = 0;  // variable to store the value coming from the sensor
  26.  
  27.  void setup() {
  28.  lcd.begin(16, 2);
  29.  }
  30.  
  31.  void loop() {
  32.    lcd.setCursor(0, 0);
  33.    lcd.print("Pot. Value:");
  34.    
  35.    // percent symbol
  36.    lcd.setCursor(3, 1);
  37.    lcd.print("%");
  38.    // read the value from the sensor:
  39.    lcd.setCursor(0, 1);
  40.    sensorValue = analogRead(sensorPin);
  41.    // this converts the 0-1023 value to 0-100  
  42.    sensorValue = map(sensorValue, 0, 1023, 0, 100);
  43.  
  44.    // print the sensor value in % to the lcd
  45.    lcd.print(sensorValue);
  46.    // stop the program for .5 second
  47.    delay(30);
  48.    // clear screen for the next loop:
  49.    lcd.clear();  
  50.  }
clone this paste RAW Paste Data