#include <max6675.h>
//#include "max6675.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
int thermoDO = 12;
int thermoCS = 10;
int thermoCLK = 13;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
// Button configuration
const int
DECREMENT_BTN_PIN = 7,
INCREMENT_BTN_PIN = 8;
// "Heater" and "cooler" configuration
const int
RELAY_PIN = 4,
COOLER_PIN = 4;
int relayState = digitalRead(RELAY_PIN);
//----------------------------------------------------------------------------
// Controls
int targetC =100; // why Target Set....must Follow whatever Setpoint is????
//------------------------------------------------------------------------------------------------
void setup() {
// Serial (for logging)
Serial.begin (9600);
Serial.print("setup()\n");
// LCD
lcd.init();
lcd.backlight();
lcd.clear();
lcd.backlight(); // Make sure backlight is on
Serial.print("\tLCD initialized\n");
// Buttons
pinMode(INCREMENT_BTN_PIN, INPUT_PULLUP);
pinMode(DECREMENT_BTN_PIN, INPUT_PULLUP);
// Temperature Controllers
pinMode(RELAY_PIN, OUTPUT);
}
//------------------------------------------------------------------------------------------------
void loop() {
// Read Button State
bool incrementTarget = digitalRead(INCREMENT_BTN_PIN);
bool decrementTarget = digitalRead(DECREMENT_BTN_PIN);
bool wait = incrementTarget || decrementTarget;
// Configure
if (incrementTarget) {
targetC += 10;
}
// if (targetC > 250 ){targetC = 250;}
if (decrementTarget) {
targetC -= 10;
}
// if (targetC < 10 ) {targetC = 10;}
const char symbol = 'C';
const int target = targetC;
//------------------------------------------------------------------------------
// Read Sensor Data
float temperature = thermocouple.readCelsius();// return Celsius
Serial.print("\t" + String(temperature) + "°" + symbol + "% \n");
//-----------------------------------------------------------------------------
// Write out to LCD
lcd.setCursor(0, 0);
Serial.print ("Temp: " + String(temperature));
lcd.print ("Temp: ");
lcd.print(round(temperature));
lcd.print(" / ");
Serial.print ("Target: " + String(target) + ".00" + symbol);
lcd.print (target);
// Activate Temperature Control
if (round(target) > round(temperature))
digitalWrite(RELAY_PIN, LOW);
else //digitalWrite(HEATER_PIN, LOW);
if (round(target) < round(temperature))
digitalWrite(RELAY_PIN, HIGH);
int relayState = digitalRead(4);
if (relayState == HIGH)
{
Serial.println("LOW");
} else {
Serial.println("HIGH");
}
lcd.setCursor(0, 1);
if (relayState== HIGH)
{
lcd.print ("Relay OFF");
} else {
lcd.print ("Relay ON");
}
// Pause to allow finger to lift from button(s)
if (wait) delay(500);
}