/*-----( Import needed libraries )-----*/
#include <LiquidCrystal.h>
/*-----( Declare objects )-----*/
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //These are the pins used on this shield
int up = 11;
int down = 12;
const int NO = 13;
int plus = 0;// variable for reading the pin status
int minus = 0;
int counter = 20;
int currentState = 0;
int previousState = 0;
void setup() /*----( SETUP: RUNS ONCE )----*/
{
lcd.begin(16, 2); // start the lcd object
pinMode(up, INPUT); // declare pushbutton as input
pinMode(down, INPUT);
pinMode(NO, OUTPUT);
}/*--(end setup )---*/
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
{
lcd.setCursor(0,1);
lcd.print(counter);
// read the input on analog pin 0:
int Tval = analogRead(A1);
plus = digitalRead(up); // read input value
minus = digitalRead(down);
if (plus == HIGH) {
currentState = 1;
} // check if the plus is HIGH (button released)
else {
currentState = 0;
} // plus
if(currentState != previousState){
if(currentState == 1){
counter = counter + 1;
lcd.clear();
lcd.setCursor(0,1);
lcd.print(counter);
}
}
if (minus == HIGH) {
currentState = 1;
} // check if the minus is HIGH (button released)
else {
currentState = 0;
} //minus
if(currentState != previousState){
if(currentState == 1){
counter = counter -1;
lcd.clear();
lcd.setCursor(0,1);
lcd.print(counter);
}
}
previousState = currentState;
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float temp = (5 * Tval * 100) / 1024;
// print out the value you read:
lcd.setCursor(0,0);
lcd.print(temp);
lcd.setCursor(2,0);
lcd.print("C ");
float contact = (counter - temp);
if (contact >=1)
{
digitalWrite(NO, HIGH);
}
else {
digitalWrite(NO, LOW);
}
delay(1000);
}
when i try the thermometer code separate everything works fine. when i put it in my thermostat code i get strange readings at 32° C it becomes unreadable on the lcd. With the serial monitor it shows minus degrees. Can anyone explain what is wrong with the code.
I have every function of the code working fine but when i combine everything it goes wrong
thx