Commit bd440b67 authored by service-config's avatar service-config

Mixer

parent 919194c6
...@@ -7,22 +7,30 @@ ...@@ -7,22 +7,30 @@
//#define DHTPIN 2 // What pin we're connected to //#define DHTPIN 2 // What pin we're connected to
//#define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT11 // DHT 11
#define ponto1 A4// #define ponto1 A4//
#define ponto2 A5// //#define ponto2 A5//
#define R1 462.0 //#define R1 99.45
#define R2 460.0 //#define R2 100.2
#define R3 460.0 //#define R3 100.05
#define calibragem 3.8515352672 //#define calibragem 12.709066573
float amostra1;// float amostra1;//
float amostra2;//
float diferenca;
float temperatura, temperatura1;// float temperatura, temperatura1;//
float tabela[] = {100.00, 100.39, 100.78, 101.17, 101.56, 101.95, 102.34, 102.73, 103.12, 103.51, 103.90, 104.29, 104.68, 105.07, 105.46, 105.85, 106.24, 106.63, 107.02, 107.40, 107.79, 108.18, 108.57, 108.96, 109.35, 109.73, 110.12, 110.51, 110.90, 111.29, 111.67, 112.06, 112.45, 112.83, 113.22, 113.61, 114.00, 114.38, 114.77, 115.15, 115.54, 115.93, 116.31, 116.70, 117.08, 117.47, 117.86, 118.24, 118.63, 119.01, 119.40, 119.78, 120.17, 120.55, 120.94, 121.32, 121.71, 122.09, 122.47, 122.86, 123.24, 123.63, 124.01, 124.39, 124.78, 125.16, 125.54, 125.93, 126.31, 126.69, 127.08, 127.46, 127.84, 128.22, 128.61, 128.99, 129.37, 129.75, 130.13, 130.52, 130.90, 131.28, 131.66, 132.04, 132.42, 132.80, 133.18, 133.57, 133.95, 134.33, 134.71, 135.09, 135.47, 135.85, 136.23, 136.61, 136.99, 137.37, 137.75, 138.13, 138.51, 138.88, 139.26, 139.64, 140.02, 140.40, 140.78, 141.16, 141.54, 141.91, 142.29, 142.67, 143.05, 143.43, 143.80, 144.18, 144.56, 144.94, 145.31, 145.69, 146.07, 146.44, 146.82, 147.20, 147.57, 147.95, 148.33, 148.70, 149.08, 149.46, 149.83, 150.21, 150.58, 150.96, 151.33, 151.71, 152.08, 152.46, 152.83, 153.21, 153.58, 153.96, 154.33, 154.71, 155.08, 155.46, 155.83, 156.20, 156.58, 156.95, 157.33, 157.70, 158.07, 158.45, 158.82, 159.19, 159.56, 159.94, 160.31, 160.68, 150.00, 160.00, 161.05, 161.43, 161.80, 162.17, 162.54, 162.91, 163.29, 163.66, 164.03, 164.40, 164.77, 165.14, 165.51, 165.89, 166.26, 166.63, 167.00, 167.37, 167.74, 168.11, 168.48, 168.85, 169.22, 169.59, 169.96, 170.33, 170.70, 171.07, 171.43, 171.80, 172.17, 172.54, 172.91, 173.28, 173.65, 174.02, 174.38, 174.75, 175.12, 175.49, 175.86, 176.22, 176.59, 176.96, 177.33, 177.69, 178.06, 178.43, 178.79, 179.16}; float tabela[] = {100.00, 100.39, 100.78, 101.17, 101.56, 101.95, 102.34, 102.73, 103.12, 103.51, 103.90, 104.29, 104.68, 105.07, 105.46, 105.85, 106.24, 106.63, 107.02, 107.40, 107.79, 108.18, 108.57, 108.96, 109.35, 109.73, 110.12, 110.51, 110.90, 111.29, 111.67, 112.06, 112.45, 112.83, 113.22, 113.61, 114.00, 114.38, 114.77, 115.15, 115.54, 115.93, 116.31, 116.70, 117.08, 117.47, 117.86, 118.24, 118.63, 119.01, 119.40, 119.78, 120.17, 120.55, 120.94, 121.32, 121.71, 122.09, 122.47, 122.86, 123.24, 123.63, 124.01, 124.39, 124.78, 125.16, 125.54, 125.93, 126.31, 126.69, 127.08, 127.46, 127.84, 128.22, 128.61, 128.99, 129.37, 129.75, 130.13, 130.52, 130.90, 131.28, 131.66, 132.04, 132.42, 132.80, 133.18, 133.57, 133.95, 134.33, 134.71, 135.09, 135.47, 135.85, 136.23, 136.61, 136.99, 137.37, 137.75, 138.13, 138.51, 138.88, 139.26, 139.64, 140.02, 140.40, 140.78, 141.16, 141.54, 141.91, 142.29, 142.67, 143.05, 143.43, 143.80, 144.18, 144.56, 144.94, 145.31, 145.69, 146.07, 146.44, 146.82, 147.20, 147.57, 147.95, 148.33, 148.70, 149.08, 149.46, 149.83, 150.21, 150.58, 150.96, 151.33, 151.71, 152.08, 152.46, 152.83, 153.21, 153.58, 153.96, 154.33, 154.71, 155.08, 155.46, 155.83, 156.20, 156.58, 156.95, 157.33, 157.70, 158.07, 158.45, 158.82, 159.19, 159.56, 159.94, 160.31, 160.68, 150.00, 160.00, 161.05, 161.43, 161.80, 162.17, 162.54, 162.91, 163.29, 163.66, 164.03, 164.40, 164.77, 165.14, 165.51, 165.89, 166.26, 166.63, 167.00, 167.37, 167.74, 168.11, 168.48, 168.85, 169.22, 169.59, 169.96, 170.33, 170.70, 171.07, 171.43, 171.80, 172.17, 172.54, 172.91, 173.28, 173.65, 174.02, 174.38, 174.75, 175.12, 175.49, 175.86, 176.22, 176.59, 176.96, 177.33, 177.69, 178.06, 178.43, 178.79, 179.16};
//float amostras[] = {630.00,630.00,630.00}; //,630.00,630.00,630.00,630.00,630.00,630.00,630.00,630.00,630.00,630.00,630.00,630.00,630.00,630.00,630.00,630.00,630.00};
float Va;
float Rx;
/*
float amostra2;//
float diferenca;
float tensaoPorAmostra; float tensaoPorAmostra;
float Vg; float Vg;
float Vs; float Vs;
float a; float a;
float Rx; float Rx;
*/
// ++++++++++++++++++++++++ Library - DHT ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Library - DHT ++++++++++++++++++++++++
// ++++++++++++++++++++++++ Library - LiquidCrystal_I2C ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Library - LiquidCrystal_I2C ++++++++++++++++++++++++
#include <Wire.h> #include <Wire.h>
...@@ -42,8 +50,17 @@ float Rx; ...@@ -42,8 +50,17 @@ float Rx;
// ++++++++++++++++++++++++ Library - LiquidCrystal_I2C ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Library - LiquidCrystal_I2C ++++++++++++++++++++++++
// ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++
#include <PID_v1.h> #include <PID_v1.h>
#define HEATING_ELEMENT 24 #define HEATING_ELEMENT 24
// ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++
// ++++++++++++++++++++++++ Temperature ++++++++++++++++++++++++
#define TEMPERATURE_MAX_POSITION 120
// ++++++++++++++++++++++++ Temperature ++++++++++++++++++++++++
// ++++++++++++++++++++++++ Mixer ++++++++++++++++++++++++
#define MIXER_PIN 12
#define MIXER_MAX_POSITION 255
const int mixerPin = 12;
const int mixerMaxSpeed = 255;
// ++++++++++++++++++++++++ Mixer ++++++++++++++++++++++++
// ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++ // ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++
#define SETTING_WELCOME_TIMEOUT 2000 #define SETTING_WELCOME_TIMEOUT 2000
#define MENU_MAX_DEPTH 10 #define MENU_MAX_DEPTH 10
...@@ -61,8 +78,8 @@ int n = 1; ...@@ -61,8 +78,8 @@ int n = 1;
LiquidCrystal_I2C lcd(LCD_I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); LiquidCrystal_I2C lcd(LCD_I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
// ++++++++++++++++++++++++ Library - LiquidCrystal_I2C ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Library - LiquidCrystal_I2C ++++++++++++++++++++++++
// ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++
volatile int virtualPosition = 0; volatile int rotaryEncoderVirtualPosition = 0;
volatile int maxPosition = 120; //volatile int rotaryEncoderMaxPosition = 120;
volatile int menuSize = 2; volatile int menuSize = 2;
const int PinCLK = 3; // Used for generating interrupts using CLK signal const int PinCLK = 3; // Used for generating interrupts using CLK signal
const int PinDT = 22; // Used for reading DT signal const int PinDT = 22; // Used for reading DT signal
...@@ -76,12 +93,16 @@ double Setpoint, Input, Output; ...@@ -76,12 +93,16 @@ double Setpoint, Input, Output;
float Kp = 200; float Kp = 200;
float Ki = 50; float Ki = 50;
float Kd = 0; float Kd = 0;
PID myPID(&Input, &Output, &Setpoint,Kp,Ki,Kd, DIRECT); //PID myPID(&Input, &Output, &Setpoint,Kp,Ki,Kd, DIRECT);
//PID myPID(&Input, &Output, &Setpoint,1000,50,0, DIRECT); //PID myPID(&Input, &Output, &Setpoint,1000,50,0, DIRECT);
PID myPID(&Input, &Output, &Setpoint,200,50,0, DIRECT);
int WindowSize = 5000; int WindowSize = 1000;
unsigned long windowStartTime; unsigned long windowStartTime;
// ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++
// ++++++++++++++++++++++++ Mixer ++++++++++++++++++++++++
//const int mixerSpeed = 130;
// ++++++++++++++++++++++++ Mixer ++++++++++++++++++++++++
// ++++++++++++++++++++++++ Error ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Error ++++++++++++++++++++++++
enum sys_error { enum sys_error {
no_error, no_error,
...@@ -92,6 +113,7 @@ enum sys_error { ...@@ -92,6 +113,7 @@ enum sys_error {
sys_error error = no_error; sys_error error = no_error;
// ++++++++++++++++++++++++ Error ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Error ++++++++++++++++++++++++
// ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++ // ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++
// global // global
enum state_machine { enum state_machine {
state_welcome, state_welcome,
...@@ -99,9 +121,11 @@ enum state_machine { ...@@ -99,9 +121,11 @@ enum state_machine {
state_manual_time, state_manual_time,
state_manual_temperature, state_manual_temperature,
state_manual_mode, state_manual_mode,
state_manual_mixer,
state_error state_error
}; };
state_machine state = state_welcome; state_machine state = state_welcome;
// menu // menu
enum main_menu_list { enum main_menu_list {
main_manual, main_manual,
...@@ -120,16 +144,16 @@ enum auto_menu_list { ...@@ -120,16 +144,16 @@ enum auto_menu_list {
auto_back auto_back
}; };
int menu_position[MENU_MAX_DEPTH]= {MENU_INIT_VALUES}; int menu_position[MENU_MAX_DEPTH]= {MENU_INIT_VALUES};
// cooking // cooking
//int cookTime = 600;
//int cookTemperature = 100;
int cookTime = 3600;
int cookTemperature = 70;
enum cook_mode_list { enum cook_mode_list {
quick_start, quick_start,
start_at_temperature start_at_temperature
}; };
int cookTime = 3600;
int cookTemperature = 36;
cook_mode_list cookMode = quick_start; cook_mode_list cookMode = quick_start;
int cookMixerSpeed = 130;
// ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++ // ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++
// ++++++++++++++++++++++++ Global Variables ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Global Variables ++++++++++++++++++++++++
//float currentTemperatureCelsius; //float currentTemperatureCelsius;
...@@ -146,76 +170,109 @@ void isr () { // Interrupt service routine is executed when ...@@ -146,76 +170,109 @@ void isr () { // Interrupt service routine is executed when
// If interrupts come faster than 5ms, assume it's a bounce and ignore // If interrupts come faster than 5ms, assume it's a bounce and ignore
if ((interruptTime - lastInterruptTime) > 5) { if ((interruptTime - lastInterruptTime) > 5) {
switch(state) { switch(state) {
// Input of rotay encoder controling menus
case state_manual_mode: case state_manual_mode:
case state_menu: { case state_menu: {
if (!digitalRead(PinDT)) { if (!digitalRead(PinDT)) {
virtualPosition = (virtualPosition + 1); rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition + 1);
} }
else { else {
virtualPosition = virtualPosition - 1; rotaryEncoderVirtualPosition = rotaryEncoderVirtualPosition - 1;
} }
if (virtualPosition >= menuSize) { if (rotaryEncoderVirtualPosition >= menuSize) {
virtualPosition = 0; rotaryEncoderVirtualPosition = 0;
} }
if (virtualPosition < 0) { if (rotaryEncoderVirtualPosition < 0) {
virtualPosition = menuSize -1; rotaryEncoderVirtualPosition = menuSize -1;
} }
break; break;
} }
// Input of rotay encoder controling time variables
case state_manual_time: { case state_manual_time: {
if (!digitalRead(PinDT)) { if (!digitalRead(PinDT)) {
if(virtualPosition >= 60) { if(rotaryEncoderVirtualPosition >= 60) {
virtualPosition = (virtualPosition + 30); rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition + 30);
} }
else { else {
virtualPosition = (virtualPosition + 1); rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition + 1);
} }
} }
else { else {
if(virtualPosition == 0) { if(rotaryEncoderVirtualPosition == 0) {
virtualPosition = (virtualPosition + 60); rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition + 60);
} }
else { else {
if(virtualPosition >= 90) { if(rotaryEncoderVirtualPosition >= 90) {
virtualPosition = (virtualPosition - 30); rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition - 30);
} }
else { else {
virtualPosition = virtualPosition - 1; rotaryEncoderVirtualPosition = rotaryEncoderVirtualPosition - 1;
} }
} }
} }
if (virtualPosition > 7200) { if (rotaryEncoderVirtualPosition > 7200) {
virtualPosition = 7200; rotaryEncoderVirtualPosition = 7200;
} }
if (virtualPosition < 0) { if (rotaryEncoderVirtualPosition < 0) {
virtualPosition = 0; rotaryEncoderVirtualPosition = 0;
} }
break; break;
} }
// Input of rotay encoder controling integer variables within a range between 0 and rotaryEncoderMaxPosition
case state_manual_mixer:
case state_manual_temperature: { case state_manual_temperature: {
if (!digitalRead(PinDT)) { if (!digitalRead(PinDT)) {
if ((interruptTime - lastInterruptTime) < 10) { if ((interruptTime - lastInterruptTime) < 10) {
virtualPosition = (virtualPosition + 5); rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition + 5);
} }
else { else {
virtualPosition = (virtualPosition + 1); rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition + 1);
} }
} }
else { else {
if ((interruptTime - lastInterruptTime) < 10) { if ((interruptTime - lastInterruptTime) < 10) {
virtualPosition = (virtualPosition - 5); rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition - 5);
} }
else { else {
virtualPosition = (virtualPosition - 1); rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition - 1);
} }
} }
if (virtualPosition > maxPosition) { if (rotaryEncoderVirtualPosition > rotaryEncoderMaxPosition) {
virtualPosition = maxPosition; rotaryEncoderVirtualPosition = rotaryEncoderMaxPosition;
} }
if (virtualPosition < 0) { if (rotaryEncoderVirtualPosition < 0) {
virtualPosition = 0; rotaryEncoderVirtualPosition = 0;
}
break;
}
case state_manual_mixer: {
if (!digitalRead(PinDT)) {
if ((interruptTime - lastInterruptTime) < 10) {
rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition + 5);
}
else {
rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition + 1);
}
}
else {
if ((interruptTime - lastInterruptTime) < 10) {
rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition - 5);
}
else {
rotaryEncoderVirtualPosition = (rotaryEncoderVirtualPosition - 1);
}
}
if (rotaryEncoderVirtualPosition > mixerMaxSpeed) {
rotaryEncoderVirtualPosition = mixerMaxSpeed;
}
if (rotaryEncoderVirtualPosition < 0) {
rotaryEncoderVirtualPosition = 0;
} }
break; break;
...@@ -262,6 +319,13 @@ void setup() { ...@@ -262,6 +319,13 @@ void setup() {
//turn the PID on //turn the PID on
myPID.SetMode(AUTOMATIC); myPID.SetMode(AUTOMATIC);
// ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++ // ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++
// ++++++++++++++++++++++++ Mixer ++++++++++++++++++++++++
pinMode(mixerPin, OUTPUT);
analogWrite(mixerPin, mixerSpeed);
// ++++++++++++++++++++++++ Mixer ++++++++++++++++++++++++
// ++++++++++++++++++++++++ Temperature Sensor PT100 ++++++++++++++++++++++++
analogReference(EXTERNAL);
// ++++++++++++++++++++++++ Temperature Sensor PT100 ++++++++++++++++++++++++
Serial.begin(9600); Serial.begin(9600);
Serial.println("Let's start Brewing!"); Serial.println("Let's start Brewing!");
} }
...@@ -279,7 +343,7 @@ void loop() { ...@@ -279,7 +343,7 @@ void loop() {
break; break;
} }
case state_manual_time: { /*case state_manual_time: {
//runManualTime(); //runManualTime();
break; break;
...@@ -289,6 +353,11 @@ void loop() { ...@@ -289,6 +353,11 @@ void loop() {
break; break;
} }
case state_manual_mixer: {
//runManualTemp();
break;
}*/
case state_error: { case state_error: {
runError(); runError();
...@@ -312,8 +381,6 @@ void runWelcome() { ...@@ -312,8 +381,6 @@ void runWelcome() {
delay(SETTING_WELCOME_TIMEOUT); delay(SETTING_WELCOME_TIMEOUT);
//state = state_manual_temp;
//state = state_manual_time;
state = state_menu; state = state_menu;
} }
...@@ -328,7 +395,7 @@ void runMenu() { ...@@ -328,7 +395,7 @@ void runMenu() {
cookTemperature = getTemperature(cookTemperature); cookTemperature = getTemperature(cookTemperature);
menu_position[1] = -1; menu_position[1] = -1;
virtualPosition = manual_temperature; rotaryEncoderVirtualPosition = manual_temperature;
break; break;
} }
...@@ -337,7 +404,7 @@ void runMenu() { ...@@ -337,7 +404,7 @@ void runMenu() {
cookTime = getTimer(cookTime); cookTime = getTimer(cookTime);
menu_position[1] = -1; menu_position[1] = -1;
virtualPosition = manual_time; rotaryEncoderVirtualPosition = manual_time;
break; break;
} }
...@@ -360,7 +427,16 @@ void runMenu() { ...@@ -360,7 +427,16 @@ void runMenu() {
} }
menu_position[1] = -1; menu_position[1] = -1;
virtualPosition = manual_mode; rotaryEncoderVirtualPosition = manual_mode;
break;
}
case manual_mixer: {
// do work
cookMixerSpeed = getMixerSpeed(cookMixerSpeed);
menu_position[1] = -1;
rotaryEncoderVirtualPosition = manual_time;
break; break;
} }
...@@ -369,7 +445,7 @@ void runMenu() { ...@@ -369,7 +445,7 @@ void runMenu() {
runStart(); runStart();
menu_position[1] = -1; menu_position[1] = -1;
virtualPosition = manual_start; rotaryEncoderVirtualPosition = manual_start;
break; break;
} }
...@@ -377,14 +453,13 @@ void runMenu() { ...@@ -377,14 +453,13 @@ void runMenu() {
menu_position[0] = -1; menu_position[0] = -1;
menu_position[1] = -1; menu_position[1] = -1;
virtualPosition = manual_back; rotaryEncoderVirtualPosition = manual_back;
break; break;
} }
default: { default: {
// reset menu variables // reset menu variables
//virtualPosition = 0; menuSize = 6;
menuSize = 5;
// display menu // display menu
lcd.clear(); lcd.clear();
...@@ -392,7 +467,7 @@ void runMenu() { ...@@ -392,7 +467,7 @@ void runMenu() {
lcd.print("Manual Menu"); lcd.print("Manual Menu");
while(true) { while(true) {
switch(virtualPosition) { switch(rotaryEncoderVirtualPosition) {
case manual_temperature: { case manual_temperature: {
lcd.setCursor (0,1); // go to start of 2nd line lcd.setCursor (0,1); // go to start of 2nd line
lcd.print("-> Temperature "); lcd.print("-> Temperature ");
...@@ -411,6 +486,12 @@ void runMenu() { ...@@ -411,6 +486,12 @@ void runMenu() {
delay(100); delay(100);
break; break;
} }
case manual_mixer: {
lcd.setCursor (0,1); // go to start of 2nd line
lcd.print("-> Mixer Speed ");
delay(100);
break;
}
case manual_start: { case manual_start: {
lcd.setCursor (0,1); // go to start of 2nd line lcd.setCursor (0,1); // go to start of 2nd line
lcd.print("-> Start "); lcd.print("-> Start ");
...@@ -426,12 +507,12 @@ void runMenu() { ...@@ -426,12 +507,12 @@ void runMenu() {
default: { default: {
//lcd.setCursor (0,1); // go to start of 2nd line //lcd.setCursor (0,1); // go to start of 2nd line
//lcd.print("*** Error ***"); //lcd.print("*** Error ***");
virtualPosition = 0; rotaryEncoderVirtualPosition = 0;
} }
} }
if (!(digitalRead(PinSW))) { // check if pushbutton is pressed if (!(digitalRead(PinSW))) { // check if pushbutton is pressed
menu_position[1] = virtualPosition; menu_position[1] = rotaryEncoderVirtualPosition;
while (!digitalRead(PinSW)) {} // wait til switch is released while (!digitalRead(PinSW)) {} // wait til switch is released
delay(10); // debounce delay(10); // debounce
break; break;
...@@ -447,7 +528,7 @@ void runMenu() { ...@@ -447,7 +528,7 @@ void runMenu() {
// do work // do work
menu_position[1] = -1; menu_position[1] = -1;
virtualPosition = auto_recipe; rotaryEncoderVirtualPosition = auto_recipe;
break; break;
} }
...@@ -455,7 +536,7 @@ void runMenu() { ...@@ -455,7 +536,7 @@ void runMenu() {
// do work // do work
menu_position[1] = -1; menu_position[1] = -1;
virtualPosition = auto_start; rotaryEncoderVirtualPosition = auto_start;
break; break;
} }
...@@ -465,13 +546,13 @@ void runMenu() { ...@@ -465,13 +546,13 @@ void runMenu() {
menu_position[1] = -1; menu_position[1] = -1;
// set menu position // set menu position
virtualPosition = main_auto; rotaryEncoderVirtualPosition = main_auto;
break; break;
} }
default: { default: {
// reset menu variables // reset menu variables
//virtualPosition = 0; //rotaryEncoderVirtualPosition = 0;
menuSize = 3; menuSize = 3;
// display menu // display menu
...@@ -480,7 +561,7 @@ void runMenu() { ...@@ -480,7 +561,7 @@ void runMenu() {
lcd.print("Automatic Menu"); lcd.print("Automatic Menu");
while(true) { while(true) {
switch(virtualPosition) { switch(rotaryEncoderVirtualPosition) {
case auto_recipe: { case auto_recipe: {
lcd.setCursor (0,1); // go to start of 2nd line lcd.setCursor (0,1); // go to start of 2nd line
lcd.print("-> Recipe "); lcd.print("-> Recipe ");
...@@ -502,12 +583,12 @@ void runMenu() { ...@@ -502,12 +583,12 @@ void runMenu() {
default: { default: {
//lcd.setCursor (0,1); // go to start of 2nd line //lcd.setCursor (0,1); // go to start of 2nd line
//lcd.print("*** Error ***"); //lcd.print("*** Error ***");
virtualPosition = 0; rotaryEncoderVirtualPosition = 0;
} }
} }
if (!(digitalRead(PinSW))) { // check if pushbutton is pressed if (!(digitalRead(PinSW))) { // check if pushbutton is pressed
menu_position[1] = virtualPosition; menu_position[1] = rotaryEncoderVirtualPosition;
while (!digitalRead(PinSW)) {} // wait til switch is released while (!digitalRead(PinSW)) {} // wait til switch is released
delay(10); // debounce delay(10); // debounce
break; break;
...@@ -519,7 +600,7 @@ void runMenu() { ...@@ -519,7 +600,7 @@ void runMenu() {
} }
default: { default: {
// reset menu variables // reset menu variables
//virtualPosition = 0; //rotaryEncoderVirtualPosition = 0;
menuSize = 2; menuSize = 2;
// display menu // display menu
...@@ -528,7 +609,7 @@ void runMenu() { ...@@ -528,7 +609,7 @@ void runMenu() {
lcd.print("Main Menu"); lcd.print("Main Menu");
while(true) { while(true) {
switch(virtualPosition) { switch(rotaryEncoderVirtualPosition) {
case main_manual: { case main_manual: {
lcd.setCursor (0,1); // go to start of 2nd line lcd.setCursor (0,1); // go to start of 2nd line
lcd.print("-> Manual "); lcd.print("-> Manual ");
...@@ -544,12 +625,12 @@ void runMenu() { ...@@ -544,12 +625,12 @@ void runMenu() {
default: { default: {
//lcd.setCursor (0,1); // go to start of 2nd line //lcd.setCursor (0,1); // go to start of 2nd line
//lcd.print("*** Error ***"); //lcd.print("*** Error ***");
virtualPosition = 0; rotaryEncoderVirtualPosition = 0;
} }
} }
if (!(digitalRead(PinSW))) { // check if pushbutton is pressed if (!(digitalRead(PinSW))) { // check if pushbutton is pressed
menu_position[0] = virtualPosition; menu_position[0] = rotaryEncoderVirtualPosition;
while (!digitalRead(PinSW)) {} // wait til switch is released while (!digitalRead(PinSW)) {} // wait til switch is released
delay(10); // debounce delay(10); // debounce
break; break;
...@@ -564,10 +645,10 @@ int getTimer(int init) { ...@@ -564,10 +645,10 @@ int getTimer(int init) {
// set operation state // set operation state
state = state_manual_time; state = state_manual_time;
virtualPosition = init; rotaryEncoderVirtualPosition = init;
// initialize variables // initialize variables
int lastCount = 0; int rotaryEncoderPreviousPosition = 0;
int minutes = 0; int minutes = 0;
int seconds = 0; int seconds = 0;
...@@ -587,10 +668,10 @@ int getTimer(int init) { ...@@ -587,10 +668,10 @@ int getTimer(int init) {
} }
// display current timer // display current timer
if (virtualPosition != lastCount) { if (rotaryEncoderVirtualPosition != rotaryEncoderPreviousPosition) {
lastCount = virtualPosition; rotaryEncoderPreviousPosition = rotaryEncoderVirtualPosition;
minutes = virtualPosition/60; minutes = rotaryEncoderVirtualPosition/60;
seconds = virtualPosition-minutes*60; seconds = rotaryEncoderVirtualPosition-minutes*60;
lcd.setCursor (0,LCD_Y-1); lcd.setCursor (0,LCD_Y-1);
lcd.print(" "); lcd.print(" ");
...@@ -605,7 +686,7 @@ int getTimer(int init) { ...@@ -605,7 +686,7 @@ int getTimer(int init) {
} }
state = initialState; state = initialState;
return virtualPosition; return rotaryEncoderVirtualPosition;
} }
int getTemperature(int init) { int getTemperature(int init) {
...@@ -613,10 +694,10 @@ int getTemperature(int init) { ...@@ -613,10 +694,10 @@ int getTemperature(int init) {
// set operation state // set operation state
state = state_manual_temperature; state = state_manual_temperature;
virtualPosition = init; rotaryEncoderVirtualPosition = init;
// initialize variables // initialize variables
int lastCount = 0; int rotaryEncoderPreviousPosition = 0;
// Setup Screen // Setup Screen
lcd.clear(); lcd.clear();
...@@ -625,6 +706,8 @@ int getTemperature(int init) { ...@@ -625,6 +706,8 @@ int getTemperature(int init) {
lcd.setCursor (0,LCD_Y-1); lcd.setCursor (0,LCD_Y-1);
lcd.print(" 0 *C"); lcd.print(" 0 *C");
rotaryEncoderMaxPosition = TEMPERATURE_MAX_POSITION;
while(true) { while(true) {
// Check for timer set // Check for timer set
if (!(digitalRead(PinSW))) { // check if pushbutton is pressed if (!(digitalRead(PinSW))) { // check if pushbutton is pressed
...@@ -634,27 +717,27 @@ int getTemperature(int init) { ...@@ -634,27 +717,27 @@ int getTemperature(int init) {
} }
// display current timer // display current timer
if (virtualPosition != lastCount) { if (rotaryEncoderVirtualPosition != rotaryEncoderPreviousPosition) {
lastCount = virtualPosition; rotaryEncoderPreviousPosition = rotaryEncoderVirtualPosition;
lcd.setCursor (0,LCD_Y-1); lcd.setCursor (0,LCD_Y-1);
lcd.print(" "); lcd.print(" ");
if(virtualPosition<10) { if(rotaryEncoderVirtualPosition<10) {
lcd.print(" "); lcd.print(" ");
} }
else { else {
if(virtualPosition<100) { if(rotaryEncoderVirtualPosition<100) {
lcd.print(" "); lcd.print(" ");
} }
} }
lcd.print(virtualPosition); lcd.print(rotaryEncoderVirtualPosition);
lcd.print(" *C"); lcd.print(" *C");
lcd.println(" "); lcd.println(" ");
} }
} }
state = initialState; state = initialState;
return virtualPosition; return rotaryEncoderVirtualPosition;
} }
int getMode() { int getMode() {
...@@ -664,10 +747,10 @@ int getMode() { ...@@ -664,10 +747,10 @@ int getMode() {
// set operation state // set operation state
state = state_manual_mode; state = state_manual_mode;
menuSize = 2; menuSize = 2;
virtualPosition = cookMode; rotaryEncoderVirtualPosition = cookMode;
// initialize variables // initialize variables
int lastCount = 0; int rotaryEncoderPreviousPosition = 0;
// Setup Screen // Setup Screen
lcd.clear(); lcd.clear();
...@@ -685,12 +768,12 @@ int getMode() { ...@@ -685,12 +768,12 @@ int getMode() {
} }
// display current timer // display current timer
if (virtualPosition != lastCount) { if (rotaryEncoderVirtualPosition != rotaryEncoderPreviousPosition) {
lastCount = virtualPosition; rotaryEncoderPreviousPosition = rotaryEncoderVirtualPosition;
lcd.setCursor (0,LCD_Y-1); lcd.setCursor (0,LCD_Y-1);
switch(virtualPosition) { switch(rotaryEncoderVirtualPosition) {
case quick_start: { case quick_start: {
lcd.print(" Quick Start "); lcd.print(" Quick Start ");
...@@ -711,28 +794,87 @@ int getMode() { ...@@ -711,28 +794,87 @@ int getMode() {
state = initialState; state = initialState;
menuSize = initialMenuSize; menuSize = initialMenuSize;
return virtualPosition; return rotaryEncoderVirtualPosition;
}
int getMixerSpeed(int init) {
state_machine initialState = state;
// set operation state
state = state_manual_mixer;
rotaryEncoderVirtualPosition = init;
// initialize variables
int rotaryEncoderPreviousPosition = 0;
int mixerSpeed = 0;
// Setup Screen
lcd.clear();
lcd.home();
lcd.print("Set Mixer Speed");
lcd.setCursor (0,LCD_Y-1);
lcd.print(" 000");
rotaryEncoderMaxPosition = MIXER_MAX_POSITION;
while(true) {
// Check for timer set
if (!(digitalRead(PinSW))) { // check if pushbutton is pressed
while (!digitalRead(PinSW)) {} // wait til switch is released
delay(10); // debounce
break;
}
// display current timer
if (rotaryEncoderVirtualPosition != rotaryEncoderPreviousPosition) {
rotaryEncoderPreviousPosition = rotaryEncoderVirtualPosition;
lcd.setCursor (0,LCD_Y-1);
lcd.print(" ");
//lcd.print(minutes);
//lcd.print(":");
if(rotaryEncoderVirtualPosition<100) {
lcd.print("0");
if(rotaryEncoderVirtualPosition<10) {
lcd.print("0");
}
}
lcd.print(rotaryEncoderVirtualPosition);
lcd.println(" ");
}
}
state = initialState;
return rotaryEncoderVirtualPosition;
} }
void runStart() { void runStart() {
// Configure environment
long runCurrentTemperature; // Working environment variables
float runCurrentTemperature;
long runTargetTemperature; long runTargetTemperature;
unsigned long runStartTime; unsigned long runStartTime;
unsigned long runTargetTime; unsigned long runTargetTime;
cook_mode_list runCurrentMode; cook_mode_list runCurrentMode;
// Configure environment
boolean clockStart = false; boolean clockStart = false;
boolean clockEnd = false; boolean clockEnd = false;
// Iterative work
while(true) { while(true) {
// Build Instructions // Build Instructions
switch(menu_position[0]) { switch(menu_position[0]) {
case main_manual: { case main_manual: {
// everything is set, lets run!
// whenever changes are made to the cook variables, they must be applied to the running variables
runTargetTemperature = cookTemperature; runTargetTemperature = cookTemperature;
runTargetTime = cookTime; runTargetTime = cookTime;
runCurrentMode = cookMode; runCurrentMode = cookMode;
runMixerSpeed = cookMixerSpeed;
// check if time ended and is time to stop and return to menu
if(clockStart && clockEnd) { if(clockStart && clockEnd) {
delay(1000); delay(1000);
return; return;
...@@ -741,7 +883,26 @@ void runStart() { ...@@ -741,7 +883,26 @@ void runStart() {
break; break;
} }
case main_auto: { case main_auto: {
// set the next instruction // get the next instruction
// if it's time for a new instruction
// if human interaction is required
// display message
// sound buzzer
// check if rotary encoder press to continue
// check what variables are afected
// check what the new values are
// apply the values
// if it's NOT time for a new instruction
//delay(1000);
break; break;
} }
...@@ -753,7 +914,8 @@ void runStart() { ...@@ -753,7 +914,8 @@ void runStart() {
} }
} }
// Run Instructions // ************ Run Instructions ************
// Setup LCD // Setup LCD
lcd.clear(); lcd.clear();
lcd.home(); lcd.home();
...@@ -770,149 +932,128 @@ void runStart() { ...@@ -770,149 +932,128 @@ void runStart() {
lcd.print("Wait 00:00"); lcd.print("Wait 00:00");
} }
//int lastCount = 0; while(true) {
amostra1 = analogRead(ponto1);
while(true) { float Vs = 4.965; //4.9345;
//Serial.println("From second while"); float Vin = 8.84; //8.8345;
// Wait a few seconds between measurements. float adcStepCount = 1024.0;
//delay(100); float R1 = 149.3;
float Rl = 3.37;
/* Read temperature from sensor float R_OpTemp = 19.7; //21.597; //24.37;
runCurrentTemperature = dht.readTemperature(); // Reading temperature
if (isnan(runCurrentTemperature)) { // Check if any reads failed and exit early (to try again).
// Got an error
state = state_error;
error = catastrofic_failure_sensor_temperature;
return;
}
*/
amostra1= analogRead(ponto1); Va = amostra1 * Vs / adcStepCount;
amostra2= analogRead(ponto2); //Rx = 151.5 * Va / ( 11.01 - Va ) - 30;
Serial.print("O valor das entradas sao: [");
Serial.print(amostra1); Rx = R1 / ( Vin / Va - 1.0) - Rl - R_OpTemp;
Serial.print(", ");
Serial.print(amostra2); int i;
Serial.println("]"); float i_f;
int tabelaSize = sizeof(tabela) / sizeof(float);
diferenca = amostra2 - amostra1; for( i = 0, i_f = 0.0; i <= tabelaSize; i++, i_f++) {
Serial.print("diferenca: ["); if((tabela[i]) > Rx) {
Serial.print(diferenca, 6); if(i == 0) {
tensaoPorAmostra = 5.0 / 1024.0; runCurrentTemperature = -1.0;
Serial.print("] tensao por amortra: ["); }
Serial.print(tensaoPorAmostra, 6); else {
Vg = ( diferenca ) * tensaoPorAmostra; if(i == tabelaSize) {
Serial.print("] Vg: ["); runCurrentTemperature = 210.0;
Serial.print(Vg, 6); }
Vs = 5.0; else {
Serial.print("] Vs: ["); runCurrentTemperature = (i_f - 1.0) + ((Rx - tabela[i-1])/(tabela[i] - tabela[i-1]));
Serial.print(Vs); }
a = R2 / (R1 + R2) - Vg / Vs; }
Serial.print("] a: [");
Serial.print(a, 6);
Rx = (a * R3) / (1 - a);
Serial.print("] Rx: [");
Serial.print(Rx, 6);
Rx = Rx - calibragem;
int i;
int tabelaSize = sizeof(tabela) / sizeof(float);
for( i = 0; i <= tabelaSize; i++) {
if((tabela[i]) > Rx) {
if(i == 0) {
runCurrentTemperature = -1.0;
}
else {
if(i == tabelaSize) {
runCurrentTemperature = 210.0;
}
else {
runCurrentTemperature = (i - 1) + ((Rx - tabela[i-1])/(tabela[i] - tabela[i-1]));
//temperatura = map(Rx, tabela[i-1], tabela[i], i-1, i); break;
} }
} }
break; /*
} Serial.print("O valor das entradas sao: [");
} Serial.print(amostra1);
Serial.print(", ");
Serial.print(amostra2);
Serial.print("]");
/* Initialize target temperature with current temperature Serial.print("diferenca: [");
if(runTargetTemperature<0) { Serial.print(diferenca, 6);
runTargetTemperature = runCurrentTemperature; Serial.print("] tensao por amortra: [");
virtualPosition = runCurrentTemperature; Serial.print(tensaoPorAmostra, 6);
}*/ Serial.print("] Vg: [");
Serial.print(Vg, 6);
/* Read push button from the rotary encoder Serial.print("] Vs: [");
if (!(digitalRead(PinSW))) { // check if pushbutton is pressed Serial.print(Vs);
virtualPosition = currentTemperatureCelsius; // if YES, then reset counter to ZERO Serial.print("] a: [");
while (!digitalRead(PinSW)) {} // wait til switch is released Serial.print(a, 6);
delay(10); // debounce Serial.print("] Rx: [");
Serial.println("Reset"); // Using the word RESET instead of COUNT here to find out a buggy encoder Serial.print(Rx, 6);
}*/ */
/* Read target temperature from the rotary encoder
if (virtualPosition != lastCount) {
lastCount = virtualPosition;
runTargetTemperature = virtualPosition;
Serial.print("Count: ");
Serial.println(virtualPosition);
}*/
// Operate the heating element // Operate the heating element
Input = runCurrentTemperature; Input = runCurrentTemperature;
Setpoint = runTargetTemperature; Setpoint = runTargetTemperature;
myPID.Compute(); myPID.Compute();
/************************************************ // Get time and use as "date" of the sensor readings
* turn the output pin on/off based on pid output
************************************************/
unsigned long now = millis(); unsigned long now = millis();
// Check if it's time to vary the pulse width modulation and if so do it by shifting the "Relay in ON" Window
if(now - windowStartTime>WindowSize) if(now - windowStartTime>WindowSize)
{ //time to shift the Relay Window {
windowStartTime += WindowSize; windowStartTime += WindowSize;
} }
// Check if the "date" is inside the "Relay ON" window and turn it ON; if not, turn it OFF
if(Output > now - windowStartTime) { if(Output > now - windowStartTime) {
digitalWrite(HEATING_ELEMENT,HIGH); digitalWrite(HEATING_ELEMENT,HIGH);
if(Output != 0) { if(Output != 0) {
/* Serial.print("O valor das entradas sao: [");
Serial.print(amostra1);
Serial.print("] Va[");
Serial.print(Va,6);
Serial.print("] Rx[");
Serial.print(Rx,6);
Serial.print("] Temperature[");
Serial.print(runCurrentTemperature,6);
Serial.print("] ");
Serial.print("+++ Diff: "); Serial.print("+++ Diff: ");
Serial.print(now - windowStartTime); Serial.print(now - windowStartTime);
Serial.print(" | Output: "); Serial.print(" | Output: ");
Serial.println(Output); Serial.println(Output);
*/
} }
} }
else { else {
digitalWrite(HEATING_ELEMENT,LOW); digitalWrite(HEATING_ELEMENT,LOW);
if(Output != 0) { if(Output != 0) {
/* Serial.print("O valor das entradas sao: [");
Serial.print(amostra1);
Serial.print("] Va[");
Serial.print(Va,6);
Serial.print("] Rx[");
Serial.print(Rx,6);
Serial.print("] Temperature[");
Serial.print(runCurrentTemperature,6);
Serial.print("] ");
Serial.print("--- Diff: "); Serial.print("--- Diff: ");
Serial.print(now - windowStartTime); Serial.print(now - windowStartTime);
Serial.print(" | Output: "); Serial.print(" | Output: ");
Serial.println(Output); Serial.println(Output);
*/
}
else {
Serial.print("O valor das entradas sao: [");
Serial.print(amostra1);
Serial.print("] Va[");
Serial.print(Va,6);
Serial.print("] Rx[");
Serial.print(Rx,6);
Serial.print("] Temperature[");
Serial.print(runCurrentTemperature,6);
Serial.println("]");
} }
}
// Print status to serial connection
//Serial.print("[Temperature Sensor] ");
//Serial.print("Temperature: ");
//Serial.print(runCurrentTemperature);
//Serial.print("*C | ");
//Serial.print(runTargetTemperature);
//Serial.println("*C ");
if(runCurrentMode == start_at_temperature) {
} }
// Print status to LCD // Print status to LCD
...@@ -925,7 +1066,7 @@ void runStart() { ...@@ -925,7 +1066,7 @@ void runStart() {
lcd.print(" "); lcd.print(" ");
} }
} }
lcd.print(runCurrentTemperature); lcd.print(runCurrentTemperature, 1);
lcd.setCursor (11,0); lcd.setCursor (11,0);
if (runTargetTemperature < 10) { if (runTargetTemperature < 10) {
...@@ -938,12 +1079,13 @@ void runStart() { ...@@ -938,12 +1079,13 @@ void runStart() {
} }
lcd.print(runTargetTemperature); lcd.print(runTargetTemperature);
// Display time // Check if the target temperature has been reached so the clock can move forward.
// Start the clock for "wait" mode
if(runCurrentTemperature == runTargetTemperature && clockStart == false) { if(runCurrentTemperature == runTargetTemperature && clockStart == false) {
clockStart = true; clockStart = true;
runStartTime = now; runStartTime = now;
} }
// If the clock can move forward, calculate it's display time; if not, set it to the total cooking time
int displayTime = 0; int displayTime = 0;
if(clockStart) { if(clockStart) {
displayTime = runTargetTime - ((now - runStartTime) / 1000); displayTime = runTargetTime - ((now - runStartTime) / 1000);
...@@ -958,9 +1100,10 @@ void runStart() { ...@@ -958,9 +1100,10 @@ void runStart() {
else { else {
displayTime = runTargetTime; displayTime = runTargetTime;
} }
// Print the clock to the LCD
int minutes = displayTime/60; int minutes = displayTime/60;
int seconds = displayTime-minutes*60; int seconds = displayTime-minutes*60;
lcd.setCursor (10,1); lcd.setCursor (10,1);
//lcd.print(" "); //lcd.print(" ");
if (minutes < 10) { if (minutes < 10) {
......
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