Hello I actually have a working program which takes temperature from two sides of my reptile vivarium and turns the heat / basking lamps on/off. I have all of this working but I thought I might add setpoint control to the vivarium. I am using the Button library to handle all button presses. I think I might have to add interrupts????
I know the arduino only has two hardware interrupts so what else can I do ? Basically when I press the button I want the program to pause or something and give me the current setpoint that I just set.
Thanks in advance
#include <Button.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// LCD Serial dat wire is plugged into pin 2 TX on the Arduino
#define ONE_WIRE_BUS 10
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
Button ltspup = Button(4, PULLUP); //left setpoint up buttonon pin 4
Button ltspdown = Button(5, PULLUP); //left setpoint down button on pin 5
Button rtspup = Button(6, PULLUP); //right setpoint up button on pin 6
Button rtspdown = Button(7, PULLUP); //right setpoint down button on pin 7
int leftsetpoint;
int rightsetpoint;
void setup(void)
{
// start serial port
Serial.begin(9600);
//Serial.println("Dallas Temperature IC Control Library Demo");
//LCD Display setup
Serial.print("?c0");
delay (300);
Serial.print("?BFF");
delay(300);
Serial.print("?f");
// Start up the library
sensors.begin();
}
void loop(void)
{
int heat1Pin = 2; //Left heating
int heat2Pin = 3; //Right heating
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
// Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
//Serial.println("DONE");
Serial.print("iVivarium ver. 1.0"); // Print version number to LCD screen
delay(1000);
Serial.print("?f"); //clear screen
delay (1000);
Serial.print("Left Temperature =");//output the temperature to serial port/LCD Display
delay(1000);
Serial.print("?f");
Serial.print("?>3");
delay (1000);
Serial.print(sensors.getTempFByIndex(0));
delay(1000);
Serial.print("?f");
Serial.print("?<");
delay (1000);
Serial.print("Right Temperature =");//output the temperature to serial port/LCD Display
delay(1000);
Serial.print("?f");
Serial.print("?>3");
delay (1000);
Serial.print(sensors.getTempFByIndex(1));
delay(1000);
Serial.print("?f");
Serial.print("?<");
delay (300);
Serial.print("Status:");
Serial.print("?n"); //CRLF mothafuka
if (sensors.getTempFByIndex(0) <= leftsetpoint) //Turn Left Heat Lamp On/Off
{
digitalWrite(heat1Pin, HIGH);
Serial.print("Basking is ON!");
}
else
{
digitalWrite(heat1Pin, LOW);
Serial.print("Basking is OFF!");
}
Serial.print("?n"); //CRLF
delay(1000);
if (sensors.getTempFByIndex(1) <= rightsetpoint) //Turn Right Heat Lamp On/Off
{
digitalWrite(heat2Pin, HIGH);
Serial.print("Heat is ON!");
}
else
{
digitalWrite(heat2Pin, LOW);
Serial.print("Heat is OFF!");
}
delay(2500);
Serial.print("?f"); //Clear Screen
if (ltspup.isPressed()) // I want to take switch input to adjust setpoint of left Heat lamp
{
leftsetpoint++; // program doesn't seem to recognize the button press
delay(350);
Serial.print(leftsetpoint); //
}
if (ltspdown.isPressed())
{
leftsetpoint--;
delay(350);
Serial.print(leftsetpoint);
}
}
:-/