#define CLK 2
#define DT 3
#define SW_BTN 4
#define R_PIN 7
int lastClick = HIGH;
int temp =0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(CLK, INPUT);
pinMode(DT, INPUT);
pinMode(SW_BTN, INPUT_PULLUP);
pinMode(R_PIN, OUTPUT);
}
void loop() {
int celsius = readTemp();
int newClick = digitalRead(CLK);
if(newClick != lastClick){
lastClick = newClick;
int dtVal = digitalRead(DT);
if(newClick == LOW && dtVal == HIGH){
temp++;
Serial.println(temp);
}
if(newClick == LOW && dtVal == LOW){
temp--;
Serial.println(temp);
}
delay(50);
}
// Serial.println(digitalRead(SW_BTN));
if(digitalRead(SW_BTN) == LOW){
digitalWrite(R_PIN, HIGH);
Serial.println("activated!!");
}else{
digitalWrite(R_PIN, LOW);
}
}
int readTemp(){
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
int analogValue = analogRead(A0);
int celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
// Serial.println(celsius);
return celsius;
}