Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Takes the Analog value from a potentiometer and writes it on the screen in percentage
- The circuit:
- * LCD RS pin to digital pin 12
- * LCD Enable pin to digital pin 11
- * LCD D4 pin to digital pin 5
- * LCD D5 pin to digital pin 4
- * LCD D6 pin to digital pin 3
- * LCD D7 pin to digital pin 2
- * LCD VEE pin to ground
- * 10K resistor:
- * ends to +5V and ground
- * wiper to Analog pin 2
- */
- // use the LiquidCrystal header
- #include <LiquidCrystal.h>
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- int sensorPin = 2; // select the input pin for the potentiometer
- int sensorValue = 0; // variable to store the value coming from the sensor
- void setup() {
- lcd.begin(16, 2);
- }
- void loop() {
- lcd.setCursor(0, 0);
- lcd.print("Pot. Value:");
- // percent symbol
- lcd.setCursor(3, 1);
- lcd.print("%");
- // read the value from the sensor:
- lcd.setCursor(0, 1);
- sensorValue = analogRead(sensorPin);
- // this converts the 0-1023 value to 0-100
- sensorValue = map(sensorValue, 0, 1023, 0, 100);
- // print the sensor value in % to the lcd
- lcd.print(sensorValue);
- // stop the program for .5 second
- delay(30);
- // clear screen for the next loop:
- lcd.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement