Hi Everyone, I have one problem with temperature regulation.So, the problem is next:
I have two buttons, for plus(counter++) and minus(counter--) and temperature sensor ds18b20. I want to
give temperature with counter by pressing theese two buttons. When i press the button, counter temperature
doesn't change. It must be pressed 10 or 15 times to change. Here is the code:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#define ONE_WIRE_BUS A0
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int Celsius;
int button=7;
bool buttonState=false;
int lastState=false;
int counter=0;
LiquidCrystal lcd(12,11,5,4,3,2);
void setup() {
// put your setup code here, to run once:
pinMode(button,INPUT);
lcd.begin(16,2);
lcd.print("Celsius= ");
sensors.begin();
}
void loop() {
// put your main code here, to run repeatedly:
sensors.requestTemperatures();
Celsius=sensors.getTempCByIndex(0);
lcd.setCursor(9,0);
lcd.print(Celsius);
lcd.print(" C");
delay(500);
buttonState=digitalRead(button);
if(buttonState!=lastState){
counter++;
lcd.setCursor(9,1);
lcd.print(counter);
}
delay(5);
buttonState=lastState;
}