Commit 90cd14af authored by João Lino's avatar João Lino

some identation.

parent 4fab6c8e
...@@ -4,59 +4,59 @@ ...@@ -4,59 +4,59 @@
// ######################### SETTINGS ######################### // ######################### SETTINGS #########################
// ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++
#define HEATING_ELEMENT_DEFAULT_WINDOW_SIZE 1000 #define HEATING_ELEMENT_DEFAULT_WINDOW_SIZE 1000
#define HEATING_ELEMENT_OUTPUT_PIN 24 #define HEATING_ELEMENT_OUTPUT_PIN 24
#define HEATING_ELEMENT_MAX_HEAT_PWM_INTEGER 5 #define HEATING_ELEMENT_MAX_HEAT_PWM_INTEGER 5
#define HEATING_ELEMENT_MAX_HEAT_PWM_FLOAT 5.0 #define HEATING_ELEMENT_MAX_HEAT_PWM_FLOAT 5.0
#define HEATING_ELEMENT_MAX_WATTAGE 3000.0 // Minimum = 2000.0 #define HEATING_ELEMENT_MAX_WATTAGE 3000.0 // Minimum = 2000.0
#define HEATING_ELEMENT_AC_FREQUENCY_HZ 50.0 #define HEATING_ELEMENT_AC_FREQUENCY_HZ 50.0
// ++++++++++++++++++++++++ Temperature ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Temperature ++++++++++++++++++++++++
#define PT100_BASE_INPUT_PIN A4 #define PT100_BASE_INPUT_PIN A4
#define PT100_BASE_OUTPUT_PIN 30 #define PT100_BASE_OUTPUT_PIN 30
#define PT100_BASE_TIME_BETWEEN_READINGS 100 #define PT100_BASE_TIME_BETWEEN_READINGS 100
#define PT100_UP_INPUT_PIN A5 #define PT100_UP_INPUT_PIN A5
#define PT100_UP_OUTPUT_PIN 31 #define PT100_UP_OUTPUT_PIN 31
#define PT100_UP_TIME_BETWEEN_READINGS 100 #define PT100_UP_TIME_BETWEEN_READINGS 100
#define PT100_DOWN_INPUT_PIN A6 #define PT100_DOWN_INPUT_PIN A6
#define PT100_DOWN_OUTPUT_PIN 32 #define PT100_DOWN_OUTPUT_PIN 32
#define PT100_DOWN_TIME_BETWEEN_READINGS 100 #define PT100_DOWN_TIME_BETWEEN_READINGS 100
#define PT100_BASE_DEFAULT_ADC_VMAX 1.081 #define PT100_BASE_DEFAULT_ADC_VMAX 1.081
#define PT100_BASE_DEFAULT_VS 4.87 #define PT100_BASE_DEFAULT_VS 4.87
#define PT100_BASE_DEFAULT_R1_RESISTENCE 606.0 #define PT100_BASE_DEFAULT_R1_RESISTENCE 606.0
#define PT100_BASE_DEFAULT_LINE_RESISTENCE 0.7 #define PT100_BASE_DEFAULT_LINE_RESISTENCE 0.7
#define PT100_BASE_DEFAULT_OPERATION_RESISTENCE 0.0 #define PT100_BASE_DEFAULT_OPERATION_RESISTENCE 0.0
#define PT100_UP_DEFAULT_ADC_VMAX 1.081 #define PT100_UP_DEFAULT_ADC_VMAX 1.081
#define PT100_UP_DEFAULT_VS 4.87 #define PT100_UP_DEFAULT_VS 4.87
#define PT100_UP_DEFAULT_R1_RESISTENCE 606.0 #define PT100_UP_DEFAULT_R1_RESISTENCE 606.0
#define PT100_UP_DEFAULT_LINE_RESISTENCE 0.7 #define PT100_UP_DEFAULT_LINE_RESISTENCE 0.7
#define PT100_UP_DEFAULT_OPERATION_RESISTENCE 0.0 #define PT100_UP_DEFAULT_OPERATION_RESISTENCE 0.0
#define PT100_DOWN_DEFAULT_ADC_VMAX 1.081 #define PT100_DOWN_DEFAULT_ADC_VMAX 1.081
#define PT100_DOWN_DEFAULT_VS 4.87 #define PT100_DOWN_DEFAULT_VS 4.87
#define PT100_DOWN_DEFAULT_R1_RESISTENCE 606.0 #define PT100_DOWN_DEFAULT_R1_RESISTENCE 606.0
#define PT100_DOWN_DEFAULT_LINE_RESISTENCE 0.7 #define PT100_DOWN_DEFAULT_LINE_RESISTENCE 0.7
#define PT100_DOWN_DEFAULT_OPERATION_RESISTENCE 0.0 #define PT100_DOWN_DEFAULT_OPERATION_RESISTENCE 0.0
// ++++++++++++++++++++++++ Mixer ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Mixer ++++++++++++++++++++++++
//#define MIXER_PIN 12 //#define MIXER_PIN 12
//#define MIXER_MAX_POSITION 255 //#define MIXER_MAX_POSITION 255
// ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++
#define ROTARY_ENCODER_INTERRUPT_NUMBER 1 // On Mega2560 boards, interrupt 1 is on pin 3 #define ROTARY_ENCODER_INTERRUPT_NUMBER 1 // On Mega2560 boards, interrupt 1 is on pin 3
#define ROTARY_ENCODER_CLK_PIN 3 // Used for generating interrupts using CLK signal #define ROTARY_ENCODER_CLK_PIN 3 // Used for generating interrupts using CLK signal
#define ROTARY_ENCODER_DT_PIN 22 // Used for reading DT signal #define ROTARY_ENCODER_DT_PIN 22 // Used for reading DT signal
#define ROTARY_ENCODER_SW_PIN 23 // Used for the push button switch #define ROTARY_ENCODER_SW_PIN 23 // Used for the push button switch
#define ROTARY_ENCODER_DEBOUNCE_TIME 10 // Number of miliseconds to ignore new signals a signal is received #define ROTARY_ENCODER_DEBOUNCE_TIME 10 // Number of miliseconds to ignore new signals a signal is received
// ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++ // ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++
#define SETTING_WELCOME_TIMEOUT 100 #define SETTING_WELCOME_TIMEOUT 100
#define SETTING_MAX_INACTIVITY_TIME 3000 #define SETTING_MAX_INACTIVITY_TIME 3000
#define MENU_MAX_DEPTH 10 #define MENU_MAX_DEPTH 10
#define MENU_INIT_VALUES -1,-1,-1,-1,-1,-1,-1,-1,-1,-1 #define MENU_INIT_VALUES -1,-1,-1,-1,-1,-1,-1,-1,-1,-1
#define MENU_SIZE_MAIN_MENU 17 #define MENU_SIZE_MAIN_MENU 17
#define SETTING_SERIAL_MONITOR_BAUD_RATE 9600 #define SETTING_SERIAL_MONITOR_BAUD_RATE 9600
#define SETTING_SERIAL_MONITOR_WELCOME_MESSAGE "Let's start Brewing!" #define SETTING_SERIAL_MONITOR_WELCOME_MESSAGE "Let's start Brewing!"
// ######################### LIBRARIES ######################### // ######################### LIBRARIES #########################
// ++++++++++++++++++++++++ LiquidCrystal_I2C ++++++++++++++++++++++++ // ++++++++++++++++++++++++ LiquidCrystal_I2C ++++++++++++++++++++++++
...@@ -64,17 +64,17 @@ ...@@ -64,17 +64,17 @@
#include <LCD.h> #include <LCD.h>
#include <LiquidCrystal_I2C.h> #include <LiquidCrystal_I2C.h>
#define LCD_I2C_ADDR 0x27 // <<----- Add your address here. Find it from I2C Scanner #define LCD_I2C_ADDR 0x27 // <<----- Add your address here. Find it from I2C Scanner
#define LCD_HORIZONTAL_RESOLUTION 16 #define LCD_HORIZONTAL_RESOLUTION 16
#define LCD_VERTICAL_RESOLUTION 2 #define LCD_VERTICAL_RESOLUTION 2
#define LCD_BACKLIGHT_PIN 3 #define LCD_BACKLIGHT_PIN 3
#define LCD_EN_PIN 2 #define LCD_EN_PIN 2
#define LCD_RW_PIN 1 #define LCD_RW_PIN 1
#define LCD_RS_PIN 0 #define LCD_RS_PIN 0
#define LCD_D4_PIN 4 #define LCD_D4_PIN 4
#define LCD_D5_PIN 5 #define LCD_D5_PIN 5
#define LCD_D6_PIN 6 #define LCD_D6_PIN 6
#define LCD_D7_PIN 7 #define LCD_D7_PIN 7
// ++++++++++++++++++++++++ PT100 +++++++++++++++++++++++++++++++++ // ++++++++++++++++++++++++ PT100 +++++++++++++++++++++++++++++++++
#include <PT100.h> #include <PT100.h>
...@@ -92,86 +92,86 @@ eSettingsMenuOptions settingsMenuOption; ...@@ -92,86 +92,86 @@ eSettingsMenuOptions settingsMenuOption;
eCookingStages cookingStage; eCookingStages cookingStage;
// ++++++++++++++++++++++++ Global Variables ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Global Variables ++++++++++++++++++++++++
boolean cooking; boolean cooking;
boolean bStageFirstRun; boolean bStageFirstRun;
int clockStartTime; int clockStartTime;
int clockCounter; int clockCounter;
int clockIgnore; int clockIgnore;
boolean clockStart; boolean clockStart;
boolean clockEnd; boolean clockEnd;
int cookTime; int cookTime;
int cookTemperature; int cookTemperature;
//cook_mode_list cookMode; //cook_mode_list cookMode;
//int cookMixerSpeed; //int cookMixerSpeed;
int cookHeatPWM; int cookHeatPWM;
int startpointTime; int startpointTime;
int betaGlucanaseTime; int betaGlucanaseTime;
int debranchingTime; int debranchingTime;
int proteolyticTime; int proteolyticTime;
int betaAmylaseTime; int betaAmylaseTime;
int alphaAmylaseTime; int alphaAmylaseTime;
int mashoutTime; int mashoutTime;
int recirculationTime; int recirculationTime;
int spargeTime; int spargeTime;
int boilTime; int boilTime;
int coolingTime; int coolingTime;
int startpointTemperature; int startpointTemperature;
int betaGlucanaseTemperature; int betaGlucanaseTemperature;
int debranchingTemperature; int debranchingTemperature;
int proteolyticTemperature; int proteolyticTemperature;
int betaAmylaseTemperature; int betaAmylaseTemperature;
int alphaAmylaseTemperature; int alphaAmylaseTemperature;
int mashoutTemperature; int mashoutTemperature;
int recirculationTemperature; int recirculationTemperature;
int spargeTemperature; int spargeTemperature;
int boilTemperature; int boilTemperature;
int coolingTemperature; int coolingTemperature;
//int menuSize; //int menuSize;
int menu_position[MENU_MAX_DEPTH] = {MENU_INIT_VALUES}; int menu_position[MENU_MAX_DEPTH] = {MENU_INIT_VALUES};
boolean refresh; boolean refresh;
boolean repaint; boolean repaint;
// ++++++++++++++++++++++++ Interrupts ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Interrupts ++++++++++++++++++++++++
static unsigned long lastInterruptTime; static unsigned long lastInterruptTime;
// ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++
volatile int rotaryEncoderVirtualPosition = 0; volatile int rotaryEncoderVirtualPosition = 0;
volatile int rotaryEncoderMaxPosition = 1; volatile int rotaryEncoderMaxPosition = 1;
volatile int rotaryEncoderMinPosition = 0; volatile int rotaryEncoderMinPosition = 0;
volatile int rotaryEncoderSingleStep = 1; volatile int rotaryEncoderSingleStep = 1;
volatile int rotaryEncoderMultiStep = 1; volatile int rotaryEncoderMultiStep = 1;
// ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++
int iWindowSize; // Time frame to operate in int iWindowSize; // Time frame to operate in
unsigned long windowStartTime; unsigned long windowStartTime;
double dWattPerPulse; double dWattPerPulse;
// ######################### INITIALIZE ######################### // ######################### INITIALIZE #########################
// ++++++++++++++++++++++++ Library - LiquidCrystal_I2C ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Library - LiquidCrystal_I2C ++++++++++++++++++++++++
LiquidCrystal_I2C lcd(LCD_I2C_ADDR, LCD_EN_PIN, LCD_RW_PIN, LCD_RS_PIN, LCD_D4_PIN, LCD_D5_PIN, LCD_D6_PIN, LCD_D7_PIN); LiquidCrystal_I2C lcd(LCD_I2C_ADDR, LCD_EN_PIN, LCD_RW_PIN, LCD_RS_PIN, LCD_D4_PIN, LCD_D5_PIN, LCD_D6_PIN, LCD_D7_PIN);
// +++++++++++++++++++++++ PT100 +++++++++++++++++++++++ // +++++++++++++++++++++++ PT100 +++++++++++++++++++++++
PT100 basePT100(PT100_BASE_OUTPUT_PIN, PT100_BASE_INPUT_PIN, PT100_BASE_TIME_BETWEEN_READINGS, PT100_BASE_DEFAULT_ADC_VMAX, PT100_BASE_DEFAULT_VS, PT100_BASE_DEFAULT_R1_RESISTENCE, PT100_BASE_DEFAULT_LINE_RESISTENCE, PT100_BASE_DEFAULT_OPERATION_RESISTENCE); PT100 basePT100(PT100_BASE_OUTPUT_PIN, PT100_BASE_INPUT_PIN, PT100_BASE_TIME_BETWEEN_READINGS, PT100_BASE_DEFAULT_ADC_VMAX, PT100_BASE_DEFAULT_VS, PT100_BASE_DEFAULT_R1_RESISTENCE, PT100_BASE_DEFAULT_LINE_RESISTENCE, PT100_BASE_DEFAULT_OPERATION_RESISTENCE);
PT100 upPT100(PT100_UP_OUTPUT_PIN, PT100_UP_INPUT_PIN, PT100_UP_TIME_BETWEEN_READINGS, PT100_UP_DEFAULT_ADC_VMAX, PT100_UP_DEFAULT_VS, PT100_UP_DEFAULT_R1_RESISTENCE, PT100_UP_DEFAULT_LINE_RESISTENCE, PT100_UP_DEFAULT_OPERATION_RESISTENCE); PT100 upPT100(PT100_UP_OUTPUT_PIN, PT100_UP_INPUT_PIN, PT100_UP_TIME_BETWEEN_READINGS, PT100_UP_DEFAULT_ADC_VMAX, PT100_UP_DEFAULT_VS, PT100_UP_DEFAULT_R1_RESISTENCE, PT100_UP_DEFAULT_LINE_RESISTENCE, PT100_UP_DEFAULT_OPERATION_RESISTENCE);
PT100 downPT100(PT100_DOWN_OUTPUT_PIN, PT100_DOWN_INPUT_PIN, PT100_DOWN_TIME_BETWEEN_READINGS, PT100_DOWN_DEFAULT_ADC_VMAX, PT100_DOWN_DEFAULT_VS, PT100_DOWN_DEFAULT_R1_RESISTENCE, PT100_DOWN_DEFAULT_LINE_RESISTENCE, PT100_DOWN_DEFAULT_OPERATION_RESISTENCE); PT100 downPT100(PT100_DOWN_OUTPUT_PIN, PT100_DOWN_INPUT_PIN, PT100_DOWN_TIME_BETWEEN_READINGS, PT100_DOWN_DEFAULT_ADC_VMAX, PT100_DOWN_DEFAULT_VS, PT100_DOWN_DEFAULT_R1_RESISTENCE, PT100_DOWN_DEFAULT_LINE_RESISTENCE, PT100_DOWN_DEFAULT_OPERATION_RESISTENCE);
// ######################### INTERRUPTS ######################### // ######################### INTERRUPTS #########################
void xSetupRotaryEncoder( eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep ) { void xSetupRotaryEncoder( eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep ) {
if( newMode >= 0 ) rotaryEncoderMode = newMode; if( newMode >= 0 ) rotaryEncoderMode = newMode;
if( newPosition >= 0 ) rotaryEncoderVirtualPosition = newPosition; if( newPosition >= 0 ) rotaryEncoderVirtualPosition = newPosition;
if( newMaxPosition >= 0 ) rotaryEncoderMaxPosition = newMaxPosition; if( newMaxPosition >= 0 ) rotaryEncoderMaxPosition = newMaxPosition;
if( newMinPosition >= 0 ) rotaryEncoderMinPosition = newMinPosition; if( newMinPosition >= 0 ) rotaryEncoderMinPosition = newMinPosition;
if( newSingleStep >= 0 ) rotaryEncoderSingleStep = newSingleStep; if( newSingleStep >= 0 ) rotaryEncoderSingleStep = newSingleStep;
if( newMultiStep >= 0 ) rotaryEncoderMultiStep = newMultiStep; if( newMultiStep >= 0 ) rotaryEncoderMultiStep = newMultiStep;
} }
void isr () { // Interrupt service routine is executed when a HIGH to LOW transition is detected on CLK void isr () { // Interrupt service routine is executed when a HIGH to LOW transition is detected on CLK
repaint = true; repaint = true;
refresh = true; refresh = true;
unsigned long interruptTime = millis(); unsigned long interruptTime = millis();
...@@ -200,7 +200,7 @@ void isr () { // Interrupt service routine is executed when a HIGH to LOW tran ...@@ -200,7 +200,7 @@ void isr () { // Interrupt service routine is executed when a HIGH to LOW tran
// Input of rotary encoder controling time variables // Input of rotary encoder controling time variables
case eRotaryEncoderMode_Time: { case eRotaryEncoderMode_Time: {
if (!digitalRead(ROTARY_ENCODER_DT_PIN)) { if (!digitalRead(ROTARY_ENCODER_DT_PIN)) {
if(rotaryEncoderVirtualPosition >= 60) { if(rotaryEncoderVirtualPosition >= 60) {
rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition + rotaryEncoderMultiStep); rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition + rotaryEncoderMultiStep);
} }
...@@ -269,113 +269,113 @@ void isr () { // Interrupt service routine is executed when a HIGH to LOW tran ...@@ -269,113 +269,113 @@ void isr () { // Interrupt service routine is executed when a HIGH to LOW tran
// ######################### START ######################### // ######################### START #########################
void xSafeHardwarePowerOff() { void xSafeHardwarePowerOff() {
// analogWrite(MIXER_PIN, 0); // Turn mixer OFF for safety // analogWrite(MIXER_PIN, 0); // Turn mixer OFF for safety
digitalWrite(HEATING_ELEMENT_OUTPUT_PIN, LOW); // Turn heading element OFF for safety digitalWrite(HEATING_ELEMENT_OUTPUT_PIN, LOW); // Turn heading element OFF for safety
//basePT100.xSafeHardwarePowerOff(); // Turn temperature sensor OFF for safety //basePT100.xSafeHardwarePowerOff(); // Turn temperature sensor OFF for safety
} }
void displayWelcome() { void displayWelcome() {
lcdPrint(" Let's start", " Brewing!"); // Write welcome lcdPrint(" Let's start", " Brewing!"); // Write welcome
delay(SETTING_WELCOME_TIMEOUT); // pause for effect delay(SETTING_WELCOME_TIMEOUT); // pause for effect
} }
void setup() { void setup() {
// ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++
pinMode (ROTARY_ENCODER_CLK_PIN,INPUT); pinMode (ROTARY_ENCODER_CLK_PIN,INPUT);
pinMode (ROTARY_ENCODER_DT_PIN, INPUT); pinMode (ROTARY_ENCODER_DT_PIN, INPUT);
pinMode (ROTARY_ENCODER_SW_PIN, INPUT); pinMode (ROTARY_ENCODER_SW_PIN, INPUT);
attachInterrupt (ROTARY_ENCODER_INTERRUPT_NUMBER, isr, FALLING); attachInterrupt (ROTARY_ENCODER_INTERRUPT_NUMBER, isr, FALLING);
// ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++
pinMode (HEATING_ELEMENT_OUTPUT_PIN, OUTPUT); pinMode (HEATING_ELEMENT_OUTPUT_PIN, OUTPUT);
digitalWrite (HEATING_ELEMENT_OUTPUT_PIN, LOW); digitalWrite (HEATING_ELEMENT_OUTPUT_PIN, LOW);
windowStartTime = millis(); windowStartTime = millis();
dWattPerPulse = HEATING_ELEMENT_MAX_WATTAGE / HEATING_ELEMENT_AC_FREQUENCY_HZ; dWattPerPulse = HEATING_ELEMENT_MAX_WATTAGE / HEATING_ELEMENT_AC_FREQUENCY_HZ;
// ++++++++++++++++++++++++ Mixer ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Mixer ++++++++++++++++++++++++
// pinMode (MIXER_PIN, OUTPUT); // pinMode (MIXER_PIN, OUTPUT);
// analogWrite (MIXER_PIN, 0); // analogWrite (MIXER_PIN, 0);
// ++++++++++++++++++++++++ Temperature Sensor PT100 ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Temperature Sensor PT100 ++++++++++++++++++++++++
//basePT100.setup(); //basePT100.setup();
/* /*
analogReference (INTERNAL1V1); // EXTERNAL && INTERNAL2V56 && INTERNAL1V1 analogReference (INTERNAL1V1); // EXTERNAL && INTERNAL2V56 && INTERNAL1V1
pinMode (PT100_OUTPUT_PIN, OUTPUT); // setup temperature sensor input pin pinMode (PT100_OUTPUT_PIN, OUTPUT); // setup temperature sensor input pin
digitalWrite (PT100_OUTPUT_PIN, LOW); // initialize sensor off digitalWrite (PT100_OUTPUT_PIN, LOW); // initialize sensor off
*/ */
// ++++++++++++++++++++++++ Serial Monitor ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Serial Monitor ++++++++++++++++++++++++
Serial.begin(SETTING_SERIAL_MONITOR_BAUD_RATE); // setup terminal baud rate Serial.begin (SETTING_SERIAL_MONITOR_BAUD_RATE); // setup terminal baud rate
Serial.println(SETTING_SERIAL_MONITOR_WELCOME_MESSAGE); // print a start message to the terminal Serial.println (SETTING_SERIAL_MONITOR_WELCOME_MESSAGE); // print a start message to the terminal
// ++++++++++++++++++++++++ Library - LiquidCrystal_I2C ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Library - LiquidCrystal_I2C ++++++++++++++++++++++++
lcd.begin (LCD_HORIZONTAL_RESOLUTION,LCD_VERTICAL_RESOLUTION); // <<----- My LCD was 16x2 lcd.begin (LCD_HORIZONTAL_RESOLUTION,LCD_VERTICAL_RESOLUTION); // <<----- My LCD was 16x2
lcd.setBacklightPin(LCD_BACKLIGHT_PIN,POSITIVE); // Setup backlight pin lcd.setBacklightPin (LCD_BACKLIGHT_PIN,POSITIVE); // Setup backlight pin
lcd.setBacklight(HIGH); // Switch on the backlight lcd.setBacklight (HIGH); // Switch on the backlight
// ######################### INITIALIZE ######################### // ######################### INITIALIZE #########################
// ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++
// set operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // set operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Disabled, 0, 0, 0, 0, 0 ); xSetupRotaryEncoder ( eRotaryEncoderMode_Disabled, 0, 0, 0, 0, 0 );
// ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++ // ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++
presetsMenuOption = ePresetsMenu_Trigo; presetsMenuOption = ePresetsMenu_Trigo;
maltMenuOption = eMaltMenu_CastleMalting_Chteau_Pilsen_2RS; maltMenuOption = eMaltMenu_CastleMalting_Chteau_Pilsen_2RS;
settingsMenuOption = eSettingsMenu_PT100_Element; settingsMenuOption = eSettingsMenu_PT100_Element;
cookingStage = eCookingStage_Startpoint; cookingStage = eCookingStage_Startpoint;
// ++++++++++++++++++++++++ Global Variables ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Global Variables ++++++++++++++++++++++++
cooking = false; cooking = false;
bStageFirstRun = true; bStageFirstRun = true;
clockStartTime = 0; clockStartTime = 0;
clockCounter = 0; clockCounter = 0;
clockIgnore = 0; clockIgnore = 0;
clockStart = false; clockStart = false;
clockEnd = false; clockEnd = false;
cookTime = 3600; cookTime = 3600;
cookTemperature = 25; cookTemperature = 25;
//cookMode = quick_start; //cookMode = quick_start;
//cookMixerSpeed = 120; //cookMixerSpeed = 120;
cookHeatPWM = 5; cookHeatPWM = 5;
startpointTime = 120; startpointTime = 120;
betaGlucanaseTime = 0; betaGlucanaseTime = 0;
debranchingTime = 0; debranchingTime = 0;
proteolyticTime = 0; proteolyticTime = 0;
betaAmylaseTime = 3600; betaAmylaseTime = 3600;
alphaAmylaseTime = 1800; alphaAmylaseTime = 1800;
mashoutTime = 300; mashoutTime = 300;
recirculationTime = 1200; recirculationTime = 1200;
spargeTime = 1200; spargeTime = 1200;
boilTime = 5400; boilTime = 5400;
coolingTime = 120; coolingTime = 120;
startpointTemperature = 45; startpointTemperature = 45;
betaGlucanaseTemperature = 40; betaGlucanaseTemperature = 40;
debranchingTemperature = 40; debranchingTemperature = 40;
proteolyticTemperature = 50; proteolyticTemperature = 50;
betaAmylaseTemperature = 60; betaAmylaseTemperature = 60;
alphaAmylaseTemperature = 70; alphaAmylaseTemperature = 70;
mashoutTemperature = 80; mashoutTemperature = 80;
recirculationTemperature = 80; recirculationTemperature = 80;
spargeTemperature = 80; spargeTemperature = 80;
boilTemperature = 100; boilTemperature = 100;
coolingTemperature = 25; coolingTemperature = 25;
refresh = true; refresh = true;
repaint = true; repaint = true;
// ++++++++++++++++++++++++ Interrupts ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Interrupts ++++++++++++++++++++++++
lastInterruptTime = 0; lastInterruptTime = 0;
// ++++++++++++++++++++++++ PID ++++++++++++++++++++++++ // ++++++++++++++++++++++++ PID ++++++++++++++++++++++++
iWindowSize = HEATING_ELEMENT_DEFAULT_WINDOW_SIZE; // Time frame to operate in iWindowSize = HEATING_ELEMENT_DEFAULT_WINDOW_SIZE; // Time frame to operate in
// ######################### Code - Run Once ######################### // ######################### Code - Run Once #########################
xSafeHardwarePowerOff(); xSafeHardwarePowerOff ();
displayWelcome(); displayWelcome ();
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_GO, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder ( eRotaryEncoderMode_Menu, eMainMenu_GO, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
} }
// ######################### START ######################### // ######################### START #########################
...@@ -383,7 +383,7 @@ void setup() { ...@@ -383,7 +383,7 @@ void setup() {
void loop() { void loop() {
unsigned long inactivityTime = millis() - lastInterruptTime; unsigned long inactivityTime = millis() - lastInterruptTime;
if(inactivityTime > SETTING_MAX_INACTIVITY_TIME) { // Inactivity check if(inactivityTime > SETTING_MAX_INACTIVITY_TIME) { // Inactivity check
if(refresh) { if(refresh) {
repaint = true; repaint = true;
refresh = false; refresh = false;
...@@ -398,32 +398,32 @@ void loop() { ...@@ -398,32 +398,32 @@ void loop() {
} }
void xPaintStatusTemplate() { void xPaintStatusTemplate() {
// Clear LCD // Clear LCD
lcd.clear(); lcd.clear();
// Position the cursor at the begining of where the temperature template goes onto the screen // Position the cursor at the begining of where the temperature template goes onto the screen
lcd.home(); lcd.home();
// Print the target and measured temperature template // Print the target and measured temperature template
if(cooking) { if(cooking) {
lcd.print("ON : 000*C/000*C"); lcd.print("ON : 000*C/000*C");
} }
else { else {
lcd.print("OFF: 000*C/000*C"); lcd.print("OFF: 000*C/000*C");
} }
// Position the cursor at the begining of where the mode and time template goes onto the screen // Position the cursor at the begining of where the mode and time template goes onto the screen
lcd.setCursor (0,LCD_VERTICAL_RESOLUTION-1); lcd.setCursor (0,LCD_VERTICAL_RESOLUTION-1);
lcd.print("**** 00:00"); lcd.print("**** 00:00");
} }
void displayStatus() { void displayStatus() {
// Check whether a template repaint is required // Check whether a template repaint is required
if(repaint) { if(repaint) {
// Repaint the LCD template // Repaint the LCD template
xPaintStatusTemplate(); xPaintStatusTemplate();
// Reset the repaint flag after the repaint has been done // Reset the repaint flag after the repaint has been done
repaint = false; repaint = false;
...@@ -487,9 +487,9 @@ void displayMainMenu() { ...@@ -487,9 +487,9 @@ void displayMainMenu() {
MainMenu_GO(); MainMenu_GO();
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_GO, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_GO, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
} }
...@@ -497,9 +497,9 @@ void displayMainMenu() { ...@@ -497,9 +497,9 @@ void displayMainMenu() {
MainMenu_Presets(); MainMenu_Presets();
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Presets, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Presets, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
} }
...@@ -507,9 +507,9 @@ void displayMainMenu() { ...@@ -507,9 +507,9 @@ void displayMainMenu() {
MainMenu_Malt(); MainMenu_Malt();
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Malt, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Malt, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
} }
...@@ -517,9 +517,9 @@ void displayMainMenu() { ...@@ -517,9 +517,9 @@ void displayMainMenu() {
MainMenu_Startpoint(); MainMenu_Startpoint();
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Startpoint, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Startpoint, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
} }
...@@ -527,9 +527,9 @@ void displayMainMenu() { ...@@ -527,9 +527,9 @@ void displayMainMenu() {
MainMenu_BetaGlucanase(); MainMenu_BetaGlucanase();
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_BetaGlucanase, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_BetaGlucanase, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
} }
...@@ -537,9 +537,9 @@ void displayMainMenu() { ...@@ -537,9 +537,9 @@ void displayMainMenu() {
MainMenu_Debranching(); MainMenu_Debranching();
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Settings, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Settings, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
} }
...@@ -547,9 +547,9 @@ void displayMainMenu() { ...@@ -547,9 +547,9 @@ void displayMainMenu() {
MainMenu_Proteolytic(); MainMenu_Proteolytic();
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Proteolytic, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Proteolytic, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
} }
...@@ -557,9 +557,9 @@ void displayMainMenu() { ...@@ -557,9 +557,9 @@ void displayMainMenu() {
MainMenu_BetaAmylase(); MainMenu_BetaAmylase();
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_BetaAmylase, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_BetaAmylase, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
} }
...@@ -567,9 +567,9 @@ void displayMainMenu() { ...@@ -567,9 +567,9 @@ void displayMainMenu() {
MainMenu_AlphaAmylase(); MainMenu_AlphaAmylase();
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_AlphaAmylase, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_AlphaAmylase, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
} }
...@@ -577,9 +577,9 @@ void displayMainMenu() { ...@@ -577,9 +577,9 @@ void displayMainMenu() {
MainMenu_Mashout(); MainMenu_Mashout();
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Mashout, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Mashout, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
} }
...@@ -587,9 +587,9 @@ void displayMainMenu() { ...@@ -587,9 +587,9 @@ void displayMainMenu() {
MainMenu_Recirculation(); MainMenu_Recirculation();
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Recirculation, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Recirculation, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
} }
...@@ -597,9 +597,9 @@ void displayMainMenu() { ...@@ -597,9 +597,9 @@ void displayMainMenu() {
MainMenu_Sparge(); MainMenu_Sparge();
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Sparge, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Sparge, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
} }
...@@ -607,9 +607,9 @@ void displayMainMenu() { ...@@ -607,9 +607,9 @@ void displayMainMenu() {
MainMenu_Boil(); MainMenu_Boil();
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Boil, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Boil, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
} }
...@@ -617,9 +617,9 @@ void displayMainMenu() { ...@@ -617,9 +617,9 @@ void displayMainMenu() {
MainMenu_Hops(); MainMenu_Hops();
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Hops, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Hops, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
} }
...@@ -627,9 +627,9 @@ void displayMainMenu() { ...@@ -627,9 +627,9 @@ void displayMainMenu() {
MainMenu_Cooling(); MainMenu_Cooling();
menu_position[0] = -1; menu_position[0] = -1;
// reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Cooling, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_Cooling, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
break; break;
} }
...@@ -749,17 +749,17 @@ void displayMainMenu() { ...@@ -749,17 +749,17 @@ void displayMainMenu() {
} }
default: { default: {
// reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // reset operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_GO, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 ); xSetupRotaryEncoder( eRotaryEncoderMode_Menu, eMainMenu_GO, MENU_SIZE_MAIN_MENU - 1, 0, 1, 1 );
} }
} }
repaint = false; repaint = false;
} }
if ((digitalRead(ROTARY_ENCODER_SW_PIN))) { // check if pushbutton is pressed if ((digitalRead(ROTARY_ENCODER_SW_PIN))) { // check if pushbutton is pressed
menu_position[0] = rotaryEncoderVirtualPosition; menu_position[0] = rotaryEncoderVirtualPosition;
while (digitalRead(ROTARY_ENCODER_SW_PIN)) {} // wait til switch is released while (digitalRead(ROTARY_ENCODER_SW_PIN)) {} // wait til switch is released
delay(10); // debounce delay(10); // debounce
break; break;
} }
} }
...@@ -767,7 +767,7 @@ void displayMainMenu() { ...@@ -767,7 +767,7 @@ void displayMainMenu() {
} }
void MainMenu_GO() { void MainMenu_GO() {
startBrewing(); startBrewing();
backToStatus(); backToStatus();
} }
...@@ -775,91 +775,91 @@ void MainMenu_GO() { ...@@ -775,91 +775,91 @@ void MainMenu_GO() {
void MainMenu_Presets() { void MainMenu_Presets() {
backToStatus(); backToStatus();
} }
void MainMenu_Malt() { void MainMenu_Malt() {
backToStatus(); backToStatus();
} }
void MainMenu_Startpoint() { void MainMenu_Startpoint() {
startpointTime = getTimer( startpointTime ); startpointTime = getTimer( startpointTime );
startpointTemperature = xSetGenericValue( startpointTemperature, 0, 120, "temperature", "*C" ); startpointTemperature = xSetGenericValue( startpointTemperature, 0, 120, "temperature", "*C" );
backToStatus(); backToStatus();
} }
void MainMenu_BetaGlucanase() { void MainMenu_BetaGlucanase() {
betaGlucanaseTime = getTimer( betaGlucanaseTime ); betaGlucanaseTime = getTimer( betaGlucanaseTime );
betaGlucanaseTemperature = xSetGenericValue( betaGlucanaseTemperature, 0, 120, "temperature", "*C" ); betaGlucanaseTemperature = xSetGenericValue( betaGlucanaseTemperature, 0, 120, "temperature", "*C" );
backToStatus(); backToStatus();
} }
void MainMenu_Debranching() { void MainMenu_Debranching() {
debranchingTime = getTimer( debranchingTime ); debranchingTime = getTimer( debranchingTime );
debranchingTemperature = xSetGenericValue( debranchingTemperature, 0, 120, "temperature", "*C" ); debranchingTemperature = xSetGenericValue( debranchingTemperature, 0, 120, "temperature", "*C" );
backToStatus(); backToStatus();
} }
void MainMenu_Proteolytic() { void MainMenu_Proteolytic() {
proteolyticTime = getTimer( proteolyticTime ); proteolyticTime = getTimer( proteolyticTime );
proteolyticTemperature = xSetGenericValue( proteolyticTemperature, 0, 120, "temperature", "*C" ); proteolyticTemperature = xSetGenericValue( proteolyticTemperature, 0, 120, "temperature", "*C" );
backToStatus(); backToStatus();
} }
void MainMenu_BetaAmylase() { void MainMenu_BetaAmylase() {
betaAmylaseTime = getTimer( betaAmylaseTime ); betaAmylaseTime = getTimer( betaAmylaseTime );
betaAmylaseTemperature = xSetGenericValue( betaAmylaseTemperature, 0, 120, "temperature", "*C" ); betaAmylaseTemperature = xSetGenericValue( betaAmylaseTemperature, 0, 120, "temperature", "*C" );
backToStatus(); backToStatus();
} }
void MainMenu_AlphaAmylase() { void MainMenu_AlphaAmylase() {
alphaAmylaseTime = getTimer( alphaAmylaseTime ); alphaAmylaseTime = getTimer( alphaAmylaseTime );
alphaAmylaseTemperature = xSetGenericValue( alphaAmylaseTemperature, 0, 120, "temperature", "*C" ); alphaAmylaseTemperature = xSetGenericValue( alphaAmylaseTemperature, 0, 120, "temperature", "*C" );
backToStatus(); backToStatus();
} }
void MainMenu_Mashout() { void MainMenu_Mashout() {
mashoutTime = getTimer( mashoutTime ); mashoutTime = getTimer( mashoutTime );
mashoutTemperature = xSetGenericValue( mashoutTemperature, 0, 120, "temperature", "*C" ); mashoutTemperature = xSetGenericValue( mashoutTemperature, 0, 120, "temperature", "*C" );
backToStatus(); backToStatus();
} }
void MainMenu_Recirculation() { void MainMenu_Recirculation() {
recirculationTime = getTimer( recirculationTime ); recirculationTime = getTimer( recirculationTime );
recirculationTemperature = xSetGenericValue( recirculationTemperature, 0, 120, "temperature", "*C" ); recirculationTemperature = xSetGenericValue( recirculationTemperature, 0, 120, "temperature", "*C" );
backToStatus(); backToStatus();
} }
void MainMenu_Sparge() { void MainMenu_Sparge() {
spargeTime = getTimer( spargeTime ); spargeTime = getTimer( spargeTime );
spargeTemperature = xSetGenericValue( spargeTemperature, 0, 120, "temperature", "*C" ); spargeTemperature = xSetGenericValue( spargeTemperature, 0, 120, "temperature", "*C" );
backToStatus(); backToStatus();
} }
void MainMenu_Boil() { void MainMenu_Boil() {
boilTime = getTimer( boilTime ); boilTime = getTimer( boilTime );
boilTemperature = xSetGenericValue( boilTemperature, 0, 120, "temperature", "*C" ); boilTemperature = xSetGenericValue( boilTemperature, 0, 120, "temperature", "*C" );
backToStatus(); backToStatus();
} }
...@@ -867,13 +867,13 @@ void MainMenu_Boil() { ...@@ -867,13 +867,13 @@ void MainMenu_Boil() {
void MainMenu_Hops() { void MainMenu_Hops() {
backToStatus(); backToStatus();
} }
void MainMenu_Cooling() { void MainMenu_Cooling() {
coolingTime = getTimer( coolingTime ); coolingTime = getTimer( coolingTime );
coolingTemperature = xSetGenericValue( coolingTemperature, 0, 120, "temperature", "*C" ); coolingTemperature = xSetGenericValue( coolingTemperature, 0, 120, "temperature", "*C" );
backToStatus(); backToStatus();
} }
...@@ -889,78 +889,78 @@ void MainMenu_Back() { ...@@ -889,78 +889,78 @@ void MainMenu_Back() {
} }
void xCountTheTime( int temperatureRange ) { void xCountTheTime( int temperatureRange ) {
// Check if the machine is in the right temperature range, for the current mode, // Check if the machine is in the right temperature range, for the current mode,
if(!(basePT100.getCurrentTemperature() > (cookTemperature - temperatureRange) && basePT100.getCurrentTemperature() < (cookTemperature + temperatureRange))) { if(!(basePT100.getCurrentTemperature() > (cookTemperature - temperatureRange) && basePT100.getCurrentTemperature() < (cookTemperature + temperatureRange))) {
clockIgnore += millis() - clockStartTime - clockCounter; clockIgnore += millis() - clockStartTime - clockCounter;
} }
// Calculate the remaining time on the clock // Calculate the remaining time on the clock
clockCounter = cookTime - ((millis() - clockStartTime - clockIgnore) / 1000); clockCounter = cookTime - ((millis() - clockStartTime - clockIgnore) / 1000);
} }
bool isTimeLeft() { bool isTimeLeft() {
if( clockCounter >= cookTime ) { if( clockCounter >= cookTime ) {
return false; return false;
} }
return true; return true;
} }
double ulWattToWindowTime( double ulAppliedWatts ) { double ulWattToWindowTime( double ulAppliedWatts ) {
double ulPulsesRequired = ulAppliedWatts / dWattPerPulse; double ulPulsesRequired = ulAppliedWatts / dWattPerPulse;
return (double)iWindowSize / 1000.0 * ulPulsesRequired; return (double)iWindowSize / 1000.0 * ulPulsesRequired;
} }
bool xRegulateTemperature() { bool xRegulateTemperature() {
double difference = basePT100.getCurrentTemperature() - cookTemperature; double difference = basePT100.getCurrentTemperature() - cookTemperature;
bool overTemperature = false; bool overTemperature = false;
double wattage = 0.0; double wattage = 0.0;
// Deviation between the cook temperature set and the cook temperature measured // Deviation between the cook temperature set and the cook temperature measured
if( difference < 0.0 ) { if( difference < 0.0 ) {
difference = difference * (-1.0); difference = difference * (-1.0);
overTemperature = true; overTemperature = true;
} }
// Calculate applied wattage, based on the distance from the target temperature // Calculate applied wattage, based on the distance from the target temperature
if( overTemperature ) { if( overTemperature ) {
// turn it off // turn it off
wattage = 0.0; wattage = 0.0;
} else { } else {
if(difference <= 1) { if(difference <= 1) {
// turn it off // turn it off
wattage = 0.0; wattage = 0.0;
} else { } else {
if(difference <= 3) { if(difference <= 3) {
// pulse lightly at 500 watt // pulse lightly at 500 watt
wattage = 500.0; wattage = 500.0;
} else { } else {
if(difference <= 6) { if(difference <= 6) {
// pulse moderately at 1000 watt // pulse moderately at 1000 watt
wattage = 1000.0; wattage = 1000.0;
} else { } else {
if(difference <= 9) { if(difference <= 9) {
// pulse hardly at 2000 watt // pulse hardly at 2000 watt
wattage = 2000.0; wattage = 2000.0;
} else { } else {
//pulse constantly at HEATING_ELEMENT_MAX_WATTAGE watt //pulse constantly at HEATING_ELEMENT_MAX_WATTAGE watt
wattage = HEATING_ELEMENT_MAX_WATTAGE; wattage = HEATING_ELEMENT_MAX_WATTAGE;
} }
} }
} }
} }
} }
// Update the recorded time for the begining of the window, if the previous window has passed // Update the recorded time for the begining of the window, if the previous window has passed
while((millis() - windowStartTime) > iWindowSize) { // Check if it's time to vary the pulse width modulation and if so do it by shifting the "Relay in ON" Window while((millis() - windowStartTime) > iWindowSize) { // Check if it's time to vary the pulse width modulation and if so do it by shifting the "Relay in ON" Window
windowStartTime += iWindowSize; windowStartTime += iWindowSize;
} }
// Apply wattage to the element at the right time // Apply wattage to the element at the right time
if( ulWattToWindowTime( wattage ) > (millis() - windowStartTime)) { if( ulWattToWindowTime( wattage ) > (millis() - windowStartTime)) {
digitalWrite(HEATING_ELEMENT_OUTPUT_PIN,HIGH); digitalWrite(HEATING_ELEMENT_OUTPUT_PIN,HIGH);
} else { } else {
digitalWrite(HEATING_ELEMENT_OUTPUT_PIN,LOW); digitalWrite(HEATING_ELEMENT_OUTPUT_PIN,LOW);
} }
} }
void xWarnClockEnded() { void xWarnClockEnded() {
...@@ -968,69 +968,69 @@ void xWarnClockEnded() { ...@@ -968,69 +968,69 @@ void xWarnClockEnded() {
} }
void xStageFirstRun( int stageTime, int stageTemperature ) { void xStageFirstRun( int stageTime, int stageTemperature ) {
// Set the clock // Set the clock
cookTime = stageTime; cookTime = stageTime;
// Set the target temperature // Set the target temperature
cookTemperature = stageTemperature; cookTemperature = stageTemperature;
// Reset the clock // Reset the clock
clockStartTime = millis(); clockStartTime = millis();
clockIgnore = 0; clockIgnore = 0;
} }
void xTransitionIntoStage_GlobalVariables(eCookingStages nextStage) { void xTransitionIntoStage_GlobalVariables(eCookingStages nextStage) {
// Reset global stage variables // Reset global stage variables
bStageFirstRun = true; bStageFirstRun = true;
cookingStage = nextStage; cookingStage = nextStage;
} }
void xTransitionIntoStage(eCookingStages nextStage) { void xTransitionIntoStage(eCookingStages nextStage) {
// Turn off all hardware that can damage itself if the machine is not cooking // Turn off all hardware that can damage itself if the machine is not cooking
xSafeHardwarePowerOff(); xSafeHardwarePowerOff();
// Warn the user a stage has ended // Warn the user a stage has ended
xWarnClockEnded(); xWarnClockEnded();
// Reset global stage variables // Reset global stage variables
xTransitionIntoStage_GlobalVariables( nextStage ); xTransitionIntoStage_GlobalVariables( nextStage );
} }
void xBasicStageOperation( int iStageTime, int iStageTemperature, int iStageTemperatureRange, eCookingStages nextStage ) { void xBasicStageOperation( int iStageTime, int iStageTemperature, int iStageTemperatureRange, eCookingStages nextStage ) {
if(bStageFirstRun) { if(bStageFirstRun) {
// Don't run this again // Don't run this again
bStageFirstRun = false; bStageFirstRun = false;
// When the stage should be skipped // When the stage should be skipped
if( iStageTime == 0) { if( iStageTime == 0) {
// Continue to the next stage // Continue to the next stage
xTransitionIntoStage_GlobalVariables( nextStage ); xTransitionIntoStage_GlobalVariables( nextStage );
// There is nothing to do, in this stage // There is nothing to do, in this stage
return; return;
} else { } else {
// Set the clock, target temperature and Reset the clock // Set the clock, target temperature and Reset the clock
xStageFirstRun( iStageTime, iStageTemperature ); xStageFirstRun( iStageTime, iStageTemperature );
} }
} else { } else {
// Account for time spent at the target temperature | Input 1: range in ºC within which the target temperature is considered to be reached // Account for time spent at the target temperature | Input 1: range in ºC within which the target temperature is considered to be reached
xCountTheTime( iStageTemperatureRange ); xCountTheTime( iStageTemperatureRange );
if( isTimeLeft() ) { if( isTimeLeft() ) {
// Do temperature control // Do temperature control
xRegulateTemperature(); xRegulateTemperature();
} else { } else {
// Continue to the next stage // Continue to the next stage
xTransitionIntoStage( nextStage ); xTransitionIntoStage( nextStage );
// There is nothing to do, in this stage // There is nothing to do, in this stage
return; return;
} }
} }
// There is nothing to do, in this iteration // There is nothing to do, in this iteration
return; return;
} }
void xWarnCookEnded() { void xWarnCookEnded() {
...@@ -1041,103 +1041,103 @@ void operateMachine() { ...@@ -1041,103 +1041,103 @@ void operateMachine() {
// Measure temperature, for effect // Measure temperature, for effect
basePT100.measure(); basePT100.measure();
upPT100.measure(); upPT100.measure();
downPT100.measure(); downPT100.measure();
// If cooking is done, return (this is a nice place to double check safety and ensure the cooking parts aren't on. // If cooking is done, return (this is a nice place to double check safety and ensure the cooking parts aren't on.
if(!cooking) { if(!cooking) {
xSafeHardwarePowerOff(); xSafeHardwarePowerOff();
return; return;
} }
// Operate the machine according to the current mode // Operate the machine according to the current mode
switch(cookingStage) { switch(cookingStage) {
case eCookingStage_Startpoint: { case eCookingStage_Startpoint: {
// A basic operation for a basic stage // A basic operation for a basic stage
xBasicStageOperation( startpointTime, startpointTemperature, 1, eCookingStage_BetaGlucanase ); xBasicStageOperation( startpointTime, startpointTemperature, 1, eCookingStage_BetaGlucanase );
// There is nothing to do, in this iteration // There is nothing to do, in this iteration
break; break;
} }
case eCookingStage_BetaGlucanase: { case eCookingStage_BetaGlucanase: {
// A basic operation for a basic stage // A basic operation for a basic stage
xBasicStageOperation( betaGlucanaseTime, betaGlucanaseTemperature, 1, eCookingStage_Debranching ); xBasicStageOperation( betaGlucanaseTime, betaGlucanaseTemperature, 1, eCookingStage_Debranching );
// There is nothing to do, in this iteration // There is nothing to do, in this iteration
break; break;
} }
case eCookingStage_Debranching: { case eCookingStage_Debranching: {
// A basic operation for a basic stage // A basic operation for a basic stage
xBasicStageOperation( debranchingTime, debranchingTemperature, 1, eCookingStage_Proteolytic ); xBasicStageOperation( debranchingTime, debranchingTemperature, 1, eCookingStage_Proteolytic );
// There is nothing to do, in this iteration // There is nothing to do, in this iteration
break; break;
} }
case eCookingStage_Proteolytic: { case eCookingStage_Proteolytic: {
// A basic operation for a basic stage // A basic operation for a basic stage
xBasicStageOperation( proteolyticTime, proteolyticTemperature, 1, eCookingStage_BetaAmylase ); xBasicStageOperation( proteolyticTime, proteolyticTemperature, 1, eCookingStage_BetaAmylase );
// There is nothing to do, in this iteration // There is nothing to do, in this iteration
break; break;
} }
case eCookingStage_BetaAmylase: { case eCookingStage_BetaAmylase: {
// A basic operation for a basic stage // A basic operation for a basic stage
xBasicStageOperation( betaAmylaseTime, betaAmylaseTemperature, 1, eCookingStage_AlphaAmylase ); xBasicStageOperation( betaAmylaseTime, betaAmylaseTemperature, 1, eCookingStage_AlphaAmylase );
// There is nothing to do, in this iteration // There is nothing to do, in this iteration
break; break;
} }
case eCookingStage_AlphaAmylase: { case eCookingStage_AlphaAmylase: {
// A basic operation for a basic stage // A basic operation for a basic stage
xBasicStageOperation( alphaAmylaseTime, alphaAmylaseTemperature, 1, eCookingStage_Mashout ); xBasicStageOperation( alphaAmylaseTime, alphaAmylaseTemperature, 1, eCookingStage_Mashout );
// There is nothing to do, in this iteration // There is nothing to do, in this iteration
break; break;
} }
case eCookingStage_Mashout: { case eCookingStage_Mashout: {
// A basic operation for a basic stage // A basic operation for a basic stage
xBasicStageOperation( mashoutTime, mashoutTemperature, 1, eCookingStage_Recirculation ); xBasicStageOperation( mashoutTime, mashoutTemperature, 1, eCookingStage_Recirculation );
// There is nothing to do, in this iteration // There is nothing to do, in this iteration
break; break;
} }
case eCookingStage_Recirculation: { case eCookingStage_Recirculation: {
// A basic operation for a basic stage // A basic operation for a basic stage
xBasicStageOperation( recirculationTime, recirculationTemperature, 1, eCookingStage_Sparge ); xBasicStageOperation( recirculationTime, recirculationTemperature, 1, eCookingStage_Sparge );
// There is nothing to do, in this iteration // There is nothing to do, in this iteration
break; break;
} }
case eCookingStage_Sparge: { case eCookingStage_Sparge: {
// A basic operation for a basic stage // A basic operation for a basic stage
xBasicStageOperation( spargeTime, spargeTemperature, 1, eCookingStage_Boil ); xBasicStageOperation( spargeTime, spargeTemperature, 1, eCookingStage_Boil );
// There is nothing to do, in this iteration // There is nothing to do, in this iteration
break; break;
} }
case eCookingStage_Boil: { case eCookingStage_Boil: {
// A basic operation for a basic stage // A basic operation for a basic stage
xBasicStageOperation( boilTime, boilTemperature, 1, eCookingStage_Cooling ); xBasicStageOperation( boilTime, boilTemperature, 1, eCookingStage_Cooling );
// There is nothing to do, in this iteration // There is nothing to do, in this iteration
break; break;
} }
case eCookingStage_Cooling: { case eCookingStage_Cooling: {
// A basic operation for a basic stage // A basic operation for a basic stage
xBasicStageOperation( coolingTime, coolingTemperature, 1, eCookingStage_Done ); xBasicStageOperation( coolingTime, coolingTemperature, 1, eCookingStage_Done );
// There is nothing to do, in this iteration // There is nothing to do, in this iteration
break; break;
} }
default : { default : {
// Update state // Update state
cooking = false; cooking = false;
// Warn the user that the cooking is done // Warn the user that the cooking is done
xWarnCookEnded(); xWarnCookEnded();
} }
} }
} }
// #################################################### Helpers ################################################################## // #################################################### Helpers ##################################################################
...@@ -1157,8 +1157,8 @@ void backToStatus() { ...@@ -1157,8 +1157,8 @@ void backToStatus() {
// #################################################### Set Variables ################################################################## // #################################################### Set Variables ##################################################################
int getTimer(int init) { int getTimer(int init) {
// set operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // set operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Time, init, 7200, 0, 1, 30 ); xSetupRotaryEncoder( eRotaryEncoderMode_Time, init, 7200, 0, 1, 30 );
// initialize variables // initialize variables
int rotaryEncoderPreviousPosition = 0; int rotaryEncoderPreviousPosition = 0;
...@@ -1174,19 +1174,19 @@ int getTimer(int init) { ...@@ -1174,19 +1174,19 @@ int getTimer(int init) {
while(true) { while(true) {
// Check if pushbutton is pressed // Check if pushbutton is pressed
if ((digitalRead(ROTARY_ENCODER_SW_PIN))) { if ((digitalRead(ROTARY_ENCODER_SW_PIN))) {
// Wait until switch is released // Wait until switch is released
while (digitalRead(ROTARY_ENCODER_SW_PIN)) {} while (digitalRead(ROTARY_ENCODER_SW_PIN)) {}
// debounce // debounce
delay(10); delay(10);
// Job is done, break the circle // Job is done, break the circle
break; break;
} else { } else {
// Don't forget to keep an eye on the cooking // Don't forget to keep an eye on the cooking
operateMachine(); operateMachine();
} }
// display current timer // display current timer
if (rotaryEncoderVirtualPosition != rotaryEncoderPreviousPosition) { if (rotaryEncoderVirtualPosition != rotaryEncoderPreviousPosition) {
...@@ -1229,19 +1229,19 @@ int getTemperature(int init) { ...@@ -1229,19 +1229,19 @@ int getTemperature(int init) {
while(true) { while(true) {
// Check if pushbutton is pressed // Check if pushbutton is pressed
if ((digitalRead(ROTARY_ENCODER_SW_PIN))) { if ((digitalRead(ROTARY_ENCODER_SW_PIN))) {
// Wait until switch is released // Wait until switch is released
while (digitalRead(ROTARY_ENCODER_SW_PIN)) {} while (digitalRead(ROTARY_ENCODER_SW_PIN)) {}
// debounce // debounce
delay(10); delay(10);
// Job is done, break the circle // Job is done, break the circle
break; break;
} else { } else {
// Don't forget to keep an eye on the cooking // Don't forget to keep an eye on the cooking
operateMachine(); operateMachine();
} }
// display current timer // display current timer
if (rotaryEncoderVirtualPosition != rotaryEncoderPreviousPosition) { if (rotaryEncoderVirtualPosition != rotaryEncoderPreviousPosition) {
...@@ -1266,9 +1266,9 @@ int getTemperature(int init) { ...@@ -1266,9 +1266,9 @@ int getTemperature(int init) {
return rotaryEncoderVirtualPosition; return rotaryEncoderVirtualPosition;
} }
int xSetGenericValue(int init, int min, int max, char *valueName, char *unit) { int xSetGenericValue(int init, int min, int max, char *valueName, char *unit) {
// set operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep // set operation state | INPUT : eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep
xSetupRotaryEncoder( eRotaryEncoderMode_Generic, init, max, min, 1, 5 ); xSetupRotaryEncoder( eRotaryEncoderMode_Generic, init, max, min, 1, 5 );
// initialize variables // initialize variables
int rotaryEncoderPreviousPosition = 0; int rotaryEncoderPreviousPosition = 0;
...@@ -1280,7 +1280,7 @@ int xSetGenericValue(int init, int min, int max, char *valueName, char *unit) { ...@@ -1280,7 +1280,7 @@ int xSetGenericValue(int init, int min, int max, char *valueName, char *unit) {
lcd.print( valueName ); lcd.print( valueName );
lcd.setCursor ( 0 , LCD_VERTICAL_RESOLUTION - 1 ); lcd.setCursor ( 0 , LCD_VERTICAL_RESOLUTION - 1 );
lcd.print( " 0 " ); lcd.print( " 0 " );
lcd.print( unit ); lcd.print( unit );
rotaryEncoderMaxPosition = TEMPERATURE_SETTING_MAX_VALUE; rotaryEncoderMaxPosition = TEMPERATURE_SETTING_MAX_VALUE;
...@@ -1288,17 +1288,17 @@ int xSetGenericValue(int init, int min, int max, char *valueName, char *unit) { ...@@ -1288,17 +1288,17 @@ int xSetGenericValue(int init, int min, int max, char *valueName, char *unit) {
// Check if pushbutton is pressed // Check if pushbutton is pressed
if ( digitalRead(ROTARY_ENCODER_SW_PIN) ) { if ( digitalRead(ROTARY_ENCODER_SW_PIN) ) {
// Wait until switch is released // Wait until switch is released
while ( digitalRead(ROTARY_ENCODER_SW_PIN) ) {} while ( digitalRead(ROTARY_ENCODER_SW_PIN) ) {}
// debounce // debounce
delay( 10 ); delay( 10 );
// Job is done, break the circle // Job is done, break the circle
break; break;
} else { } else {
// Don't forget to keep an eye on the cooking // Don't forget to keep an eye on the cooking
operateMachine(); operateMachine();
} }
// Check if there was an update by the rotary encoder // Check if there was an update by the rotary encoder
if( rotaryEncoderVirtualPosition != rotaryEncoderPreviousPosition ) { if( rotaryEncoderVirtualPosition != rotaryEncoderPreviousPosition ) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment