Ok, took me a few days to have time to get on here..
The code works great, although I haven't made many changes since I got it working, I've used the kiln for pottery and glaze, metal hardening and softening and wax mold removal.. everything I could think of doing.
The code is included below.
/*
Pin information
Analog 0 = Button
Digital 0 = MAX31885 CLK
Digital 1 = MAX31885 CS
Digital 2 = MAX31885 DO
Digital 4 = LCD DB4
Digital 5 = LCD DB5
Digital 6 = LCD DB6
Digital 7 = LCD DB7
Digital 8 = LCD RS
Digital 9 = LCD Enable
Digital 10 = LCD Backlight
Digital 13 = Heater relays
*/
/* 2013 by Rob Schilperoort
parts inspired by dfrobot LCD Keypad shield example
parts inspired by AdaFruit MAX31885 Example
*/
#include <LiquidCrystal.h>
#include "Adafruit_MAX31855.h"
int thermoDO = 2;
int thermoCS = 1;
int thermoCLK = 0;
Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
int heatmode = 0;
#define Manual 0
#define Timed 1
#define Anneal 2
#define Harden 3
#define Biscuit 4
#define Glaze 5
int targettemp = 0;
const int maxtemp = 1200;
int backlight = 0;
int err = 0;
// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
/*
lcd.setCursor(8,0);
lcd.print("Key: ");
lcd.setCursor(11,0);
lcd.print(adc_key_in);
*/
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
// For V1.1 us this threshold
/*
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;
*/
// For V1.0 comment the other threshold and use the one below:
if (adc_key_in < 50) {delay(150); return btnRIGHT;}
if (adc_key_in < 195) {delay(150); return btnUP;}
if (adc_key_in < 380) {delay(150); return btnDOWN;}
if (adc_key_in < 555) {delay(150); return btnLEFT;}
if (adc_key_in < 790) {delay(150); return btnSELECT;}
return btnNONE; // when all others fail, return this...
}
void printheatmode() {
switch (heatmode)
{
case Manual:
{
lcd.print("Manual ");
break;
}
case Timed:
{
lcd.print("Timed ");
break;
}
case Anneal:
{
lcd.print("Anneal ");
break;
}
case Harden:
{
lcd.print("Harden ");
break;
}
case Biscuit:
{
lcd.print("Biscuit");
break;
}
case Glaze:
{
lcd.print("Glaze ");
break;
}
}
}
void heatto(int temp)
{
lcd.setCursor(8,1);
lcd.print("-> ");
lcd.print(temp);
digitalWrite(13,HIGH);
unsigned long stamp = millis();
double c;
while (c<temp)
{
lcd.setCursor(13,0);
lcd.print(lround((millis()-stamp)/60000));
lcd.setCursor(0,1);
c = thermocouple.readCelsius();
if (isnan(c))
{
lcd.print("Error");
c=0;
}
else
{
lcd.print(lround(c));
lcd.print(" ");
}
delay(1000);
}
digitalWrite(13,LOW);
}
void maintain(int temp, int time)
{
int variation = (temp/50);
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(8,1);
lcd.print("= ");
lcd.setCursor(10,1);
lcd.print(temp);
unsigned long endtime = (time*60*1000)+millis();
double c;
while (millis()<endtime)
{
lcd.setCursor(13,0);
lcd.print(lround((endtime-millis())/60000));
c = thermocouple.readCelsius();
lcd.setCursor(0,1);
if (isnan(c))
{
lcd.print("Error");
c=0;
}
else
{
lcd.print(lround(c));
}
if (c>(temp+variation))
{
digitalWrite(13,LOW);
}
if (c<(temp-variation))
{
digitalWrite(13,HIGH);
}
delay(500);
}
digitalWrite(13, LOW);
}
void coolslow(int rate)
{
}
void monitor()
{
lcd.setCursor(0,1);
lcd.print("Cooldown ");
unsigned long stamp = millis();
double c;
int select = 0;
while(select==0)
{
lcd.setCursor(13,0);
lcd.print(lround((millis()-stamp)/60000));
lcd.setCursor(11,1);
c = thermocouple.readCelsius();
if (isnan(c))
{
lcd.print("Error");
c=0;
}
else
{
lcd.print(lround(c));
lcd.print(" ");
}
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnSELECT:
{
select = 1;
break;
}
}
}
}
void manualmode() {
int select = 0;
unsigned long stamp = millis();
while (select==0)
{
lcd.setCursor(13,0);
lcd.print(lround((millis()-stamp)/60000));
double c = thermocouple.readCelsius();
lcd.setCursor(0,1);
if (isnan(c))
{
lcd.print("Error");
c=0;
}
else
{
lcd.print(lround(c));
lcd.print(" ");
}
lcd.setCursor(11,1);
lcd.print(targettemp);
lcd.print(" ");
if (targettemp>c)
{
lcd.setCursor(8,1);
lcd.print("+");
digitalWrite(13,HIGH);
}
else
{
lcd.setCursor(8,1);
lcd.print("=");
digitalWrite(13,LOW);
}
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
if (targettemp<(maxtemp-99))
{
targettemp = targettemp + 100;
}
else
{
targettemp = maxtemp;
}
break;
}
case btnLEFT:
{
if (targettemp>99)
{
targettemp = targettemp - 100;
}
else
{
targettemp = 0;
}
break;
}
case btnUP:
{
if (targettemp<(maxtemp-4))
{
targettemp = targettemp + 5;
}
break;
}
case btnDOWN:
{
if (targettemp>4)
{
targettemp = targettemp - 5;
}
else
{
targettemp = 0;
}
break;
}
case btnSELECT:
{
select=1;
break;
}
}
}
}
void timedmode()
{
lcd.setCursor(0,1);
lcd.print("Target Temp:");
targettemp=500;
int select = 0;
while(select==0)
{
lcd.setCursor(13,1);
lcd.print(targettemp);
lcd.print(" ");
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
if (targettemp<(maxtemp-99))
{
targettemp = targettemp + 100;
}
else
{
targettemp = maxtemp;
}
break;
}
case btnLEFT:
{
if (targettemp>99)
{
targettemp = targettemp - 100;
}
else
{
targettemp = 0;
}
break;
}
case btnUP:
{
if (targettemp<(maxtemp-4))
{
targettemp = targettemp + 5;
}
break;
}
case btnDOWN:
{
if (targettemp>4)
{
targettemp = targettemp - 5;
}
else
{
targettemp = 0;
}
break;
}
case btnSELECT:
{
select = 1;
break;
}
}
}
lcd.setCursor(0,1);
lcd.print("Duration: ");
int duration=0;
select = 0;
while(select==0)
{
lcd.setCursor(10,1);
lcd.print(duration);
lcd.print(" ");
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
if (duration<(999-59))
{
duration = duration + 60;
}
else
{
duration = 999;
}
break;
}
case btnLEFT:
{
if (duration>59)
{
duration = duration - 60;
}
else
{
duration = 0;
}
break;
}
case btnUP:
{
if (duration<(999-4))
{
duration = duration + 5;
}
break;
}
case btnDOWN:
{
if (duration>4)
{
duration = duration - 5;
}
else
{
duration = 0;
}
break;
}
case btnSELECT:
{
select = 1;
break;
}
}
}
lcd.setCursor(0,1);
lcd.print(" ");
heatto(targettemp);
maintain(targettemp,duration);
monitor();
}
void annealmode()
{
lcd.setCursor(0,1);
lcd.print("Anneal Temp:");
targettemp=400;
int select = 0;
while(select==0)
{
lcd.setCursor(13,1);
lcd.print(targettemp);
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
if (targettemp<(maxtemp-99))
{
targettemp = targettemp + 100;
}
else
{
targettemp = maxtemp;
}
break;
}
case btnLEFT:
{
if (targettemp>99)
{
targettemp = targettemp - 100;
}
else
{
targettemp = 0;
}
break;
}
case btnUP:
{
if (targettemp<(maxtemp-4))
{
targettemp = targettemp + 5;
}
break;
}
case btnDOWN:
{
if (targettemp>4)
{
targettemp = targettemp - 5;
}
else
{
targettemp = 0;
}
break;
}
case btnSELECT:
{
select = 1;
break;
}
}
}
heatto(targettemp);
maintain(targettemp,10);
coolslow(60);
monitor();
}
void hardenmode()
{
}
void biscuitmode()
{
lcd.setCursor(0,1);
lcd.print("Temperature:");
targettemp=955;
int select = 0;
while(select==0)
{
lcd.setCursor(12,1);
lcd.print(targettemp);
lcd.print(" ");
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
if (targettemp<(maxtemp-99))
{
targettemp = targettemp + 100;
}
else
{
targettemp = maxtemp;
}
break;
}
case btnLEFT:
{
if (targettemp>99)
{
targettemp = targettemp - 100;
}
else
{
targettemp = 0;
}
break;
}
case btnUP:
{
if (targettemp<(maxtemp-4))
{
targettemp = targettemp + 5;
}
break;
}
case btnDOWN:
{
if (targettemp>4)
{
targettemp = targettemp - 5;
}
else
{
targettemp = 0;
}
break;
}
case btnSELECT:
{
select = 1;
break;
}
}
}
lcd.setCursor(0,1);
lcd.print(" ");
heatto(targettemp);
maintain(targettemp,10);
monitor();
}
void glazemode()
{
lcd.setCursor(0,1);
lcd.print("Temperature:");
targettemp=1055;
int select = 0;
while(select==0)
{
lcd.setCursor(12,1);
lcd.print(targettemp);
lcd.print(" ");
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
if (targettemp<(maxtemp-99))
{
targettemp = targettemp + 100;
}
else
{
targettemp = maxtemp;
}
break;
}
case btnLEFT:
{
if (targettemp>99)
{
targettemp = targettemp - 100;
}
else
{
targettemp = 0;
}
break;
}
case btnUP:
{
if (targettemp<(maxtemp-4))
{
targettemp = targettemp + 5;
}
break;
}
case btnDOWN:
{
if (targettemp>4)
{
targettemp = targettemp - 5;
}
else
{
targettemp = 0;
}
break;
}
case btnSELECT:
{
select = 1;
break;
}
}
}
lcd.setCursor(0,1);
lcd.print(" ");
heatto(targettemp);
maintain(targettemp,10);
monitor();
}
void setup() {
lcd.begin(16, 2); // start the library
lcd.clear();
lcd.print("Thermocontroller");
lcd.setCursor(0, 1);
lcd.print("v1 2013");
pinMode(13,OUTPUT);
digitalWrite(13,LOW);
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);
delay(1000);
int c = thermocouple.readInternal();
}
void loop() {
lcd.clear();
lcd.print("Select mode:");
heatmode=0;
int select = 0;
while(select==0)
{
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnUP:
{
heatmode++;
break;
}
case btnDOWN:
{
heatmode--;
break;
}
case btnSELECT:
{
select=1;
break;
}
}
if(heatmode==6) heatmode=0;
if(heatmode==-1) heatmode=5;
lcd.setCursor(0,1);
printheatmode();
}
lcd.clear();
printheatmode();
switch (heatmode)
{
case Manual:
{
manualmode();
break;
}
case Timed:
{
timedmode();
break;
}
case Anneal:
{
annealmode();
break;
}
case Harden:
{
hardenmode();
break;
}
case Biscuit:
{
biscuitmode();
break;
}
case Glaze:
{
glazemode();
break;
}
}
}