Now i have moved on to the next step that i wanted to do which is add a second pot that i can use to scroll through messages.
I connected the pot's center pin to anolog pin A0 and Left to gound, right to 5V both directly on the Arduino Uno.
i have tried powering both from the usb port and a 9V battery.
this works most of the time but sometimes the screen will display random characters (mostly looking like junk but sometimes repeating part of the string to be displayed or the whole string.
is this noise from somewhere? a loose connection? bad code?
let me know if you want pictures. i am doubting it is a solder issue since i had no issues with any of the example scripts.
Code: Select all
// include the library code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12); //to hold the pins of the display
int sensorPin = A0; //pin to read the selection pot
int sensorValue; //to hold the value selected
int currentMessage = 0; //to see if the message has changes since last loop through
String messages[] = {"hello","how are you?","good","me too, thanks!"}; //array of messages
void setup() {
lcd.begin(16,2); // set up the LCD's number of columns and rows
pinMode(sensorPin, INPUT); //set up the pin to read the pot
}
void loop() {
lcd.setCursor(0,0);
sensorValue = analogRead(sensorPin); //read the pot
sensorValue = map(sensorValue, 0, 1000, 0, 3); //divide the pot reading into the number of values to match the number of messages
//if statement used to check to see if value changed since last time through. if true clear old message and set currentMessage value to new message value
if (currentMessage != sensorValue) {
currentMessage = sensorValue;
lcd.clear();
}
lcd.print(messages[sensorValue]); //print the message to the display
}