Hi everyone
(If there is a solution to this already, please point me in the right direction, I don't know what to search for.)
I have an itead studio LCD shield and a LM35 temp sensor. The LCD shield has 5 buttons connected to A0 with different resistances on each button.
If I read and display the temperature(Analog pin 4), it works 100%. If I read and display the button that is pressed (Analog pin 0), it works 100%.
But as soon as I do both in the same sketch, the temp values jump around randomly and the button press affects the temp value.
What am I missing here?
This works:
void loop()
{
readTemp();
displayTemp();
delay(500);
}
void readTemp()
{
sensorValue = analogRead(TEMP_ADC_PIN);
sensorValue = round((5.0 * sensorValue * 100.0)/1024.0);
maxtemp = max(maxtemp, sensorValue);
mintemp = min(mintemp, sensorValue);
}
void displayTemp()
{
output = "Max: " + String(maxtemp) + " " + "Min: " + String(mintemp);
lcd.setCursor(0, 0);
lcd.print(output);
lcd.setCursor(0, 1);
output = String(sensorValue) + " C";
lcd.print(output);
}
and this works:
void loop()
{
byte button;
button = ReadButtons();
lcd.setCursor(15,1);
lcd.print(String(button)); //Display button press in right bottom corner.
delay(500);
}
ReadButtons() I copied from this website LCD & Keypad Shield Quickstart Guide | Freetronics, but just doing a simple analogRead on pin A0 yields the same results.
Calling ReadButtons() and readTemp() in loop causes the temp values to be random and is affected by a button press.