Hi all,
I am quit new working with Arduino. After trying to figure out the whole morning I thought it was better to ask for help at the Arduino Forum ;).
The case is:
I want to display at my LCD screen a value from 2 till 5. This should be working by turning on the potentiometer. I have made a code which is shown below (and attached). The problem is that the LCD screen still displays a value from 0 to 1023. And actually when I rotate to fast, the value is over the 1023 (for example 5430). As well I have attached the setup of the hardware.
I have lighten the green LED, but it was for testing. In the end I want that this system displays:
Value 2/3 = RED LED ON
Value 4 = YELLOW LED ON
Value 5 = GREEN LED ON
I hope someone with a better understanding then me with Arduino can help me. Thanks a lot.
#include <LiquidCrystal.h>
// Variabelen voor LED lampjes
int LED_GROEN = 10;
int LED_GEEL = 9;
int LED_ROOD = 8;
// variabele voor LCD scherm
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
Serial.begin(9600);
pinMode(LED_GROEN, OUTPUT);
pinMode(LED_GEEL, OUTPUT);
pinMode(LED_ROOD, OUTPUT);
//pinMode(buffersize, INPUT);
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.print("Buffersize ="); // Print a message to the LCD.
}
void loop() {
lcd.setCursor(0, 1); // set the cursor to column 0, line 1 (note: line 1 is the second row, since counting begins with 0):
int potValue = analogRead(A5);
int val = map(potValue, 0, 1023, 2, 5);
lcd.print(potValue);
digitalWrite(LED_GROEN, HIGH);
}
sketch_mar29a.ino (850 Bytes)