Hi,
i though that my first arduino project could be a simple fridge that had a 20x4 screen, 2 buttons to change my target temperature, and a tempsensor. but i'm running in to a problem with how to change the target temp.
the target temp won't change if i press one of the buttons, but i can get a readout on the serial from the main loop that the button is pushed, and i don't get any readouts from the "void target" but i don't quite understand how interrupt command works
Could someone help me a little bit here?
btw, i'm using pull down on the button signal
I have attached the whole code as it is right now.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define R1 2 // Peltier 1
#define R2 3 // Peltier 2
#define R3 4 // Fan + Radiator
#define uptmpb 5 // Button increase temp
#define dwntmpb 6 // Button decrease temp
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
int ftmp; //Temp inside
int maxtmp; //max temp
int settmp; //Target temp
int mintmp; //min temp
void setup() { // put your setup code here, to run once:
ftmp = 4;
settmp = 5;
mintmp = settmp - 1;
maxtmp = settmp + 1;
Serial.begin(9600);
lcd.begin(20,4);
lcd.setCursor(0,0);
lcd.print("Fridge Cooler V1");
lcd.setCursor(0,2);
delay(1000);
lcd.print("initializing");
pinMode(R1, OUTPUT);
pinMode(R2, OUTPUT);
pinMode(R3, OUTPUT);
pinMode(uptmpb, INPUT);
pinMode(dwntmpb, INPUT);
digitalWrite(R1, LOW);
digitalWrite(R2, LOW);
digitalWrite(R3, LOW);
attachInterrupt(digitalPinToInterrupt(uptmpb || dwntmpb), Target, CHANGE);
delay(1000);
}
void Target() {
if (digitalRead (uptmpb) == true){
settmp + 1;
maxtmp + 1;
mintmp + 1;
Serial.println("increase");
}
if (digitalRead (dwntmpb) == true){
settmp - 1;
maxtmp - 1;
mintmp - 1;
Serial.println("decrease");
}
}
void loop() {
// put your main code here, to run repeatedly:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Beer Fridge");
lcd.setCursor(0,1);
lcd.print("Cooling down ");
if (ftmp >= maxtmp){
digitalWrite(R1, HIGH);
digitalWrite(R2, HIGH);
digitalWrite(R3, HIGH);
}
if (ftmp <= mintmp){
digitalWrite(R1, LOW);
digitalWrite(R2, LOW);
digitalWrite(R3, LOW);
}
if (R1 || R2 || R3 == HIGH){
lcd.setCursor(15,1);
lcd.print("true");
}
lcd.setCursor(0,2);
lcd.print("Temp ");
lcd.setCursor(15,2);
lcd.print(ftmp);
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0,3);
lcd.print("Target ");
lcd.setCursor(15,3);
lcd.print(settmp);
delay(1000);
Serial.println(mintmp,"Min");
Serial.println(settmp,"Stilt");
Serial.println(maxtmp,"Maks");
Serial.println(digitalRead (uptmpb));
Serial.println(digitalRead (dwntmpb));
delay(1000);
}