Hi, I'm trying to build a heater damper controller with 3 zones. I'm new to Arduino so please forgive me if my code is hard to follow. I intend to use a Arduino MEGA with all 6 interrupts, 3 to increase the set-points and 3 to decrease them. I am currently working with a UNO and have only written two of the interrupts. The interrupt on pin 2 works ok, but will need some debouncing. But i cant get the one on pin 3 to work, please let me know if anyone can see where i went wrong. Thanks.
#include <LiquidCrystal.h>
int Damper1 = 8;
int Damper2 = 9;
int Damper3 = 10;
int Fan = 0;
volatile int SetPoint1 = 45;
volatile int SetPoint2 = 45;
volatile int SetPoint3 = 45;
float voltage = 4.88;
float tempC1 = 0;
float tempC2 = 0;
float tempC3 = 0;
float tempAC1 = 0;
float tempAC2 = 0;
float tempAC3 = 0;
int tempPin1 = 0;
int tempPin2 = 1;
int tempPin3 = 2;
float samples1[10];
float samples2[10];
float samples3[10];
int i1;
int i2;
int i3;
//volatile int changeButton = 2;
volatile int upButton1 = 2;
volatile int downButton1 = 3;
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
const int backlight = 13;
int changeButtonState = 0;
int upButton1State = 0;
int downButton1State = 0;
void setup(){
pinMode(upButton1,INPUT_PULLUP);
pinMode(downButton1,INPUT_PULLUP);
pinMode(backlight, OUTPUT);
digitalWrite(backlight, LOW);
digitalWrite(Damper1, HIGH);
digitalWrite(Damper2, HIGH);
digitalWrite(Damper3, HIGH);
attachInterrupt(digitalPinToInterrupt(upButton1),upSetPoint1,CHANGE);
attachInterrupt(digitalPinToInterrupt(downButton1),downSetPoint1,CHANGE);
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(Damper1, OUTPUT);
pinMode(Damper2, OUTPUT);
pinMode(Damper3, OUTPUT);
}
void loop(){
{
//Room 1
Serial.println("");
Serial.println("Room 1 Raw data: ");
for(i1 = 0;i1<=9;i1++){
samples1[i1] = ( voltage * analogRead(tempPin1) * 100.0) / 1024.0;
Serial.println(samples1[i1]);
tempC1 = tempC1 + samples1[i1];
delay(800);
}
tempAC1 = tempC1/10.0;
Serial.print(" Room 1 average " );
Serial.println(tempAC1);
lcd.setCursor(0, 0);
lcd.print("Setpoint 1: ");
lcd.print(SetPoint1);
lcd.setCursor(0, 1);
lcd.print("Rm 1 Temp: ");
lcd.print(tempAC1);
delay(800);
tempC1 = 0;
if (tempAC1 >= SetPoint1)
{
digitalWrite(Damper1, HIGH);
}
else if (tempAC1 <= SetPoint1-2)
{
digitalWrite(Damper1, LOW);
}
else
{
digitalWrite(Damper1, HIGH);
}
}
{
Serial.println("");
Serial.println("Room 2 Raw data: ");
for(i2 = 0;i2<=9;i2++)
{
samples2[i2] = ( voltage * analogRead(tempPin2) * 100.0) / 1024.0;
Serial.println(samples2[i2]);
tempC2 = tempC2 + samples2[i2];
delay(800);
}
tempAC2 = tempC2/10.0;
Serial.print(" Room 2 average " );
Serial.println(tempAC2);
lcd.setCursor(0, 0);
lcd.print("Setpoint 2: ");
lcd.print(SetPoint2);
lcd.setCursor(0, 1);
lcd.print("Rm 2 Temp: ");
lcd.print(tempAC2);
delay(800);
tempC2 = 0;
if (tempAC2 >= SetPoint2)
{
digitalWrite(Damper2, HIGH);
}
else if (tempAC2 <= SetPoint2-2)
{
digitalWrite(Damper2, LOW);
}
else
{
digitalWrite(Damper2, HIGH);
}
}
{
Serial.println("");
Serial.println("Room 3 Raw data: ");
for(i3 = 0;i3<=9;i3++)
{
samples3[i3] = ( voltage * analogRead(tempPin3) * 100.0) / 1024.0;
Serial.println(samples3[i3]);
tempC3 = tempC3 + samples3[i3];
delay(800);
}
tempAC3 = tempC3/10.0;
Serial.print(" Room 3 average " );
Serial.println(tempAC3);
lcd.setCursor(0, 0);
lcd.print("Setpoint 3: ");
lcd.print(SetPoint3);
lcd.setCursor(0, 1);
lcd.print("Rm 3 Temp: ");
lcd.print(tempAC3);
delay(800);
tempC3 = 0;
if (tempAC3 >= SetPoint3)
{
digitalWrite(Damper3, HIGH);
}
else if (tempAC3 <= SetPoint3-2)
{
digitalWrite(Damper3, LOW);
}
else
{
digitalWrite(Damper3, HIGH);
}
}
}
void upSetPoint1(){
upButton1State = digitalRead(upButton1);
if (upButton1State == LOW) {
digitalWrite(backlight, HIGH);
SetPoint1++;
} else {
digitalWrite(backlight, LOW);
}
lcd.setCursor(0, 0);
lcd.print("Setpoint 1: ");
lcd.print(SetPoint1);
lcd.setCursor(0, 1);
lcd.print("Rm 1 Temp: ");
lcd.print(tempAC1);
}
void downSetPoint1(){
downButton1State = digitalRead(downButton1);
if (downButton1 == LOW) {
digitalWrite(backlight, HIGH);
SetPoint1--;
} else {
digitalWrite(backlight, LOW);
}
lcd.setCursor(0, 0);
lcd.print("Setpoint 1: ");
lcd.print(SetPoint1);
lcd.setCursor(0, 1);
lcd.print("Rm 1 Temp: ");
lcd.print(tempAC1);
}