Commit b341fe27 authored by João Lino's avatar João Lino

Start from stage

Start from stage
parent 0c5f686d
......@@ -16,6 +16,7 @@ enum eRotaryEncoderMode {
// menu
enum eMenuType {
eMenuType_Main,
eMenuType_StartFromStage,
eMenuType_BeerProfile,
eMenuType_Stage,
eMenuType_Malt,
......@@ -23,7 +24,8 @@ enum eMenuType {
};
enum eMainMenuOptions {
eMainMenu_NULL,
eMainMenu_GO,
eMainMenu_GO_FROM_STAGE,
eMainMenu_GO,
eMainMenu_STOP,
eMainMenu_SKIP,
eMainMenu_BeerProfile,
......@@ -53,15 +55,15 @@ enum eStageMenuOptions {
};
enum eBeerProfileMenuOptions {
eBeerProfileMenu_NULL,
eBeerProfileMenu_Basic,
eBeerProfileMenu_Trigo,
eBeerProfileMenu_IPA,
eBeerProfileMenu_Belga,
eBeerProfileMenu_Red,
eBeerProfileMenu_APA,
eBeerProfileMenu_Custom,
eBeerProfileMenu_Back
eBeerProfileMenu_NULL,
eBeerProfileMenu_Basic,
eBeerProfileMenu_Trigo,
eBeerProfileMenu_IPA,
eBeerProfileMenu_Belga,
eBeerProfileMenu_Red,
eBeerProfileMenu_APA,
eBeerProfileMenu_Custom,
eBeerProfileMenu_Back
};
enum eMaltMenuOptions {
......@@ -73,6 +75,7 @@ enum eMaltMenuOptions {
enum eSettingsMenuOptions {
eSettingsMenu_NULL,
eSettingsMenu_Pump,
eSettingsMenu_PT100_Element,
eSettingsMenu_PT100_Up,
eSettingsMenu_PT100_Down,
......@@ -107,4 +110,4 @@ enum eBeerProfile {
eBeerProfile_Custom
};
#endif
\ No newline at end of file
#endif
......@@ -174,6 +174,11 @@ boolean displayMainMenu(LiquidCrystal_I2C *lcd, eMainMenuOptions position, boole
lcd->print("Brewery Menu");
switch(position) {
case eMainMenu_GO_FROM_STAGE: {
lcd->setCursor (0,1); // go to start of 2nd line
lcd->print("-> GO FROM STAGE");
break;
}
case eMainMenu_GO: {
lcd->setCursor (0,1); // go to start of 2nd line
lcd->print("-> GO ");
......@@ -461,4 +466,4 @@ boolean displaySettingsMenu(LiquidCrystal_I2C *lcd, eSettingsMenuOptions positio
}
return ret;
}
\ No newline at end of file
}
/*
void termometerCalibration() {
float temperaturePumpOFF = 200.0;
float temperaturePumpON = 200.0;
#ifdef DEBUG
debugPrintFunction("termometerCalibration");
#endif
for( int i = 0; i < 300; i++ ) {
basePT100.measure();
delay(100);
}
temperaturePumpOFF = basePT100.getCurrentTemperature();
analogWrite(PUMP_PIN, PUMP_SPEED_MAX);
for( int i = 0; i < 300; i++ ) {
basePT100.measure();
delay(100);
}
temperaturePumpON = basePT100.getCurrentTemperature();
analogWrite(PUMP_PIN, PUMP_SPEED_STOP);
#ifdef DEBUG
debugPrintVar("temperaturePumpOFF", temperaturePumpOFF);
debugPrintVar("temperaturePumpON", temperaturePumpON);
debugPrintVar("diff", temperaturePumpON - temperaturePumpOFF);
#endif
}
*/
\ No newline at end of file
#ifndef MELODY_h
#define MELODY_h
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
// Start by defining the relationship between note, period, & frequency.
#define _c 3830 // 261 Hz
#define _d 3400 // 294 Hz
#define _e 3038 // 329 Hz
#define _f 2864 // 349 Hz
#define _g 2550 // 392 Hz
#define _a 2272 // 440 Hz
#define _b 2028 // 493 Hz
#define _C 1912 // 523 Hz
// Define a special note, 'R', to represent a rest
#define _R 0
#define MELODY_SUPER_MARIO 1
#define MELODY_UNDERWORLD 2
#define MELODY_SUPER_MARIO_START 3
// melody[] is an array of notes, accompanied by beats[],
// which sets each note's relative length (higher #, longer note)
void buzz(int targetPin, long frequency, long length);
void sing(int s, int pin);
#endif
\ No newline at end of file
This diff is collapsed.
/*
Temperature.cpp - Library for measuring temperature with a Temperature.
Created by João Lino, June 24, 2015.
Released into the public domain.
*/
#include "Arduino.h"
#include "Temperature.h"
Temperature::Temperature(char *name,
int OutputPin_SensorPower,
int InputPin_TemperatureReading,
int TimeBetweenReadings,
float m1,
float m2,
float b1,
float b2) {
_name = name;
_OutputPin_SensorPower = OutputPin_SensorPower;
_InputPin_TemperatureReading = InputPin_TemperatureReading;
_TimeBetweenReadings = TimeBetweenReadings;
_m1 = m1;
_m2 = m2;
_b1 = b1;
_b2 = b2;
_temperatureAverage = 24.0;
_measuredTemperature = 24.0;
_lastTemperatureRead = 0;
_VoutAnalogSample = -1;
_VoutPreviousAnalogSample = -1.0;
_temperatureMeasurementsMarker = 0;
_rTemperatureMeasurementsMarker = 0;
_measuredTemperatureDeviation = 0.0;
_pump = false;
analogReference(INTERNAL1V1); // EXTERNAL && INTERNAL2V56 && INTERNAL1V1
pinMode(_OutputPin_SensorPower, OUTPUT); // setup temperature sensor input pin
digitalWrite(_OutputPin_SensorPower, LOW); // initialize sensor on
}
void Temperature::safeHardwarePowerOff() {
digitalWrite(_OutputPin_SensorPower, LOW); // Turn temperature sensor OFF for safety
}
void Temperature::measure(boolean ln) {
if(millis() - _lastTemperatureRead >= _TimeBetweenReadings) { //time to measure temperature
/** measure Vout analog sample */
digitalWrite(_OutputPin_SensorPower, HIGH); // initialize sensor on
delay(10);
_VoutAnalogSample = analogRead(_InputPin_TemperatureReading); // Get a reading
digitalWrite(_OutputPin_SensorPower, LOW); // initialize sensor on
_lastTemperatureRead = millis(); // Mark time of temperature reading
_rTemperatureMeasurementsMarker++; // Position reading buffer marker at the last updated position
if(_rTemperatureMeasurementsMarker >= TEMPERATURE_AVERAGE_VALUE_I) _rTemperatureMeasurementsMarker = 0; // Check that it has not gone out of the buffer range
_rTemperatureMeasurements[_rTemperatureMeasurementsMarker] = _VoutAnalogSample;
//workingSample = GetMedianAverage(_rTemperatureMeasurements, 6);
float workingSample = GetMedian(_rTemperatureMeasurements);
/** Calculate temperature value */
if(_pump) {
_measuredTemperature = ( workingSample - _b1 ) / _m1;
} else {
_measuredTemperature = ( workingSample - _b2 ) / _m2;
}
#ifdef DEBUG
Serial.print(_name);
Serial.print(",");
//Serial.print(_VoutAnalogSample);
//Serial.print(workingSample);
Serial.print(_measuredTemperature);
//Serial.print(GetMedianAverage(_rTemperatureMeasurements, 6));
Serial.print(",");
if(ln) Serial.println("");
#endif
}
}
float Temperature::GetMedian(int array[]){
int sorted[TEMPERATURE_AVERAGE_VALUE_I];
float value = 0.0;
for(int x = 0; x < TEMPERATURE_AVERAGE_VALUE_I; x++) {
sorted[x] = array[x];
}
//ARRANGE VALUES
for(int x = 0; x < TEMPERATURE_AVERAGE_VALUE_I; x++){
for(int y = 0; y < TEMPERATURE_AVERAGE_VALUE_I - 1; y++){
if(sorted[y]>sorted[y+1]){
int temp = sorted[y+1];
sorted[y+1] = sorted[y];
sorted[y] = temp;
}
}
}
//CALCULATE THE MEDIAN (middle number)
if(TEMPERATURE_AVERAGE_VALUE_I % 2 != 0){// is the # of elements odd?
value = (float) sorted[((TEMPERATURE_AVERAGE_VALUE_I-1)/2) + 1];
}
else{// then it's even! :)
value = ((float) ( sorted[(TEMPERATURE_AVERAGE_VALUE_I/2)] + sorted[TEMPERATURE_AVERAGE_VALUE_I/2 + 1] )) / 2.0;
}
return value;
}
float Temperature::GetMedianAverage(int array[], int range) {
int sorted[TEMPERATURE_AVERAGE_VALUE_I];
float value = 0.0;
for(int x = 0; x < TEMPERATURE_AVERAGE_VALUE_I; x++) {
sorted[x] = array[x];
}
//ARRANGE VALUES
for(int x = 0; x < TEMPERATURE_AVERAGE_VALUE_I; x++){
for(int y = 0; y < TEMPERATURE_AVERAGE_VALUE_I - 1; y++){
if(sorted[y]>sorted[y+1]){
int temp = sorted[y+1];
sorted[y+1] = sorted[y];
sorted[y] = temp;
}
}
}
//CALCULATE THE MEDIAN (middle number)
if(TEMPERATURE_AVERAGE_VALUE_I % 2 != 0){// is the # of elements odd?
int temp = ((TEMPERATURE_AVERAGE_VALUE_I+1)/2)-1;
value = (float) sorted[temp];
}
else{// then it's even! :)
value = ((float) ( sorted[(TEMPERATURE_AVERAGE_VALUE_I/2)-1] + sorted[TEMPERATURE_AVERAGE_VALUE_I/2] )) / 2.0;
}
int range_ = range;
if(range_ % 2 != 0) {// is the # of elements odd?
range_++;
}
int sum = 0;
for( int x = 0; x < range_; x++) {
sum += sorted[ (TEMPERATURE_AVERAGE_VALUE_I / 2 - range_ / 2 + x ) ];
}
value = ((float) (sum / range_));
return value;
}
float Temperature::GetMode(float new_array[]) {
int ipRepetition[TEMPERATURE_AVERAGE_VALUE_I];
for (int i = 0; i < TEMPERATURE_AVERAGE_VALUE_I; i++) {
ipRepetition[i] = 0;//initialize each element to 0
int j = 0;//
while ((j < i) && (new_array[i] != new_array[j])) {
if (new_array[i] != new_array[j]) {
j++;
}
}
(ipRepetition[j])++;
}
int iMaxRepeat = 0;
for (int i = 1; i < TEMPERATURE_AVERAGE_VALUE_I; i++) {
if (ipRepetition[i] > ipRepetition[iMaxRepeat]) {
iMaxRepeat = i;
}
}
return new_array[iMaxRepeat];
}
float Temperature::getCurrentTemperature() {
return _measuredTemperature; // - 4.41;
}
float Temperature::setPumpStatus( bool pump ) {
_pump = pump;
return _pump;
}
\ No newline at end of file
/*
Temperature.cpp - Library for measuring temperature with a Temperature.
Created by João Lino, December 22, 2015.
Released into the public domain.
*/
#include "Arduino.h"
#include "Temperature.h"
Temperature::Temperature(char *name,
int OutputPin_SensorPower,
int InputPin_TemperatureReading,
int TimeBetweenReadings) {
_name = name;
_OutputPin_SensorPower = OutputPin_SensorPower;
_InputPin_TemperatureReading = InputPin_TemperatureReading;
_TimeBetweenReadings = TimeBetweenReadings;
_ADCVmax = ADCVmax;
_temperatureAverage = 24.0;
_measuredTemperature = 24.0;
_lastTemperatureRead = 0;
_VoutAnalogSample = -1;
_VoutPreviousAnalogSample = -1.0;
_temperatureMeasurementsMarker = 0;
_rTemperatureMeasurementsMarker = 0;
_rLineMeasurementsMarker = 0;
_measuredTemperatureDeviation = 0.0;
_sampleDeviation = 0.0;
analogReference(INTERNAL1V1); // EXTERNAL && INTERNAL2V56 && INTERNAL1V1
pinMode(_OutputPin_SensorPower, OUTPUT); // setup temperature sensor input pin
digitalWrite(_OutputPin_SensorPower, LOW); // initialize sensor on
}
void Temperature::safeHardwarePowerOff() {
digitalWrite(_OutputPin_SensorPower, LOW); // Turn temperature sensor OFF for safety
digitalWrite(_OutputPin_ThirdLinePower, LOW); // Turn temperature sensor OFF for safety
}
void Temperature::measure1(boolean ln, boolean rline) {
if(millis() - _lastTemperatureRead >= _TimeBetweenReadings) { //time to measure temperature
/** measure Vout analog sample */
digitalWrite(_OutputPin_SensorPower, HIGH); // initialize sensor on
digitalWrite(_OutputPin_ThirdLinePower, HIGH); // initialize sensor on
delay(10);
_VoutAnalogSample = analogRead(_InputPin_TemperatureReading) + _sampleDeviation; // Get a reading
_VoutRAnalogSample = analogRead(_InputPin_ThirdLineReading) + _sampleDeviation; // Get a reading
digitalWrite(_OutputPin_SensorPower, LOW); // initialize sensor on
digitalWrite(_OutputPin_ThirdLinePower, LOW); // initialize sensor on
_lastTemperatureRead = millis(); // Mark time of temperature reading
_rTemperatureMeasurementsMarker++; // Position reading buffer marker at the last updated position
if(_rTemperatureMeasurementsMarker >= TEMPERATURE_AVERAGE_VALUE_I) _rTemperatureMeasurementsMarker = 0; // Check that it has not gone out of the buffer range
_rTemperatureMeasurements[_rTemperatureMeasurementsMarker] = _VoutAnalogSample;
float Vout = GetMedian(_rTemperatureMeasurements) * _ADCVmax / CONSTANT_ADC_STEP_COUNT;
float Rx = _R1 / ( _Vs / Vout - 1.0);
if(rline) {
_rLineMeasurementsMarker++; // Position reading buffer marker at the last updated position
if(_rLineMeasurementsMarker >= TEMPERATURE_AVERAGE_VALUE_I) _rLineMeasurementsMarker = 0; // Check that it has not gone out of the buffer range
_rLineMeasurements[_rLineMeasurementsMarker] = _VoutRAnalogSample;
/** Calculate temperature value */
float VoutR = GetMedian(_rLineMeasurements) * _ADCVmax / CONSTANT_ADC_STEP_COUNT;
float Rline = _R2 / ( _Vs / VoutR - 1.0);
_measuredTemperature = 1.08271 * pow(10.0, -13.0) * (3.12508 * pow(10.0, 16.0) - 5.65566 * pow(10.0, 6.0) * sqrt(3.51501 * pow(10.0, 19.0) - 4.61805 * pow(10.0, 16.0) * (Rx - Rline)));
}
else {
/** Calculate temperature value */
_measuredTemperature = 1.08271 * pow(10.0, -13.0) * (3.12508 * pow(10.0, 16.0) - 5.65566 * pow(10.0, 6.0) * sqrt(3.51501 * pow(10.0, 19.0) - 4.61805 * pow(10.0, 16.0) * Rx));
}
//xFilterNoise(_temperatureMeasurementsMarker);
/*
Serial.print("Temperature : [");
Serial.print(_name);
Serial.print("]\tVoutSample: [");
Serial.print(_VoutAnalogSample);
// Serial.print("]\tVout[");
// Serial.print(Vout,6);
// Serial.print("]\tRx[");
// Serial.print(Rx,6);
Serial.print("]\tTNow[");
Serial.print(measuredTemperatureNow,6);
Serial.print("]\tTCalc[");
Serial.print(_measuredTemperature,6);
Serial.println("] ");
*/
//Serial.print("Temperature : [");
#ifdef DEBUG
Serial.print(_name);
Serial.print(",");
Serial.print(_VoutAnalogSample);
Serial.print(",");
//Serial.print(_VoutRAnalogSample);
//Serial.print(",");
/*Serial.print(test);
Serial.print(",");
Serial.print(Rtest);
Serial.print(",");*/
/*Serial.print(Vout,6);
Serial.print(",");
Serial.print(Rx,6);
Serial.print(",");
Serial.print(measuredTemperatureNow,6);
Serial.print(",");
Serial.print(_measuredTemperature,6);
Serial.print(",");*/
if(ln) Serial.println("");
#endif
}
}
float Temperature::GetMedian(int array[]){
int sorted[TEMPERATURE_AVERAGE_VALUE_I];
float value = 0.0;
for(int x = 0; x < TEMPERATURE_AVERAGE_VALUE_I; x++) {
sorted[x] = array[x];
}
//ARRANGE VALUES
for(int x = 0; x < TEMPERATURE_AVERAGE_VALUE_I; x++){
for(int y = 0; y < TEMPERATURE_AVERAGE_VALUE_I - 1; y++){
if(sorted[y]>sorted[y+1]){
int temp = sorted[y+1];
sorted[y+1] = sorted[y];
sorted[y] = temp;
}
}
}
//CALCULATE THE MEDIAN (middle number)
if(TEMPERATURE_AVERAGE_VALUE_I % 2 != 0){// is the # of elements odd?
int temp = ((TEMPERATURE_AVERAGE_VALUE_I+1)/2)-1;
value = (float) sorted[temp];
}
else{// then it's even! :)
value = ((float) ( sorted[(TEMPERATURE_AVERAGE_VALUE_I/2)-1] + sorted[TEMPERATURE_AVERAGE_VALUE_I/2] )) / 2.0;
}
return value;
}
float Temperature::getCurrentTemperature() {
return _measuredTemperature + _measuredTemperatureDeviation;
}
float Temperature::getMeasuredTemperatureDeviation() {
return _measuredTemperatureDeviation;
}
float Temperature::setMeasuredTemperatureDeviation( float measuredTemperatureDeviation) {
if( _measuredTemperatureDeviation != measuredTemperatureDeviation ) {
_measuredTemperatureDeviation = measuredTemperatureDeviation;
for( int i = 0; i < TEMPERATURE_AVERAGE_VALUE_I; i++ ) {
_temperatureMeasurements[i] = _temperatureMeasurements[i] + ( _measuredTemperatureDeviation * -1 );
}
}
return _measuredTemperatureDeviation;
}
float Temperature::setSampleDeviation( float sampleDeviation) {
_sampleDeviation = sampleDeviation;
return _sampleDeviation;
}
\ No newline at end of file
/*
Temperature.h - Library for measuring temperature with a Temperature.
Created by João Lino, June 24, 2015.
Released into the public domain.
*/
#ifndef Temperature_h
#define Temperature_h
#include "Arduino.h"
#define DEBUG
#define CONSTANT_ADC_STEP_COUNT 1024.0
#define TEMPERATURE_AVERAGE_VALUE_I 50
#define TEMPERATURE_AVERAGE_VALUE_F 50.0
//#define TEMPERATURE_AVERATE_INIT_VALUES 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
#define TEMPERATURE_AVERATE_INIT_VALUES 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
#define TEMPERATURE_AVERATE_INIT_VALUES_I 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
#define TEMPERATURE_SETTING_MAX_VALUE 120
class Temperature
{
public:
// Temperature(Temperature_OUTPUT_PIN, Temperature_INPUT_PIN, Temperature_TIME_BETWEEN_READINGS, Temperature_DEFAULT_ADC_VMAX, Temperature_DEFAULT_VS, Temperature_DEFAULT_R1_RESISTENCE, Temperature_DEFAULT_LINE_RESISTENCE, Temperature_DEFAULT_OPERATION_RESISTENCE);
Temperature(char *name,
int OutputPin_SensorPower,
int InputPin_TemperatureReading,
int TimeBetweenReadings,
float m1,
float m2,
float b1,
float b2);
void measure(boolean ln);
void safeHardwarePowerOff();
float getCurrentTemperature();
float setPumpStatus( bool pump );
private:
char *_name;
int _OutputPin_SensorPower;
int _InputPin_TemperatureReading;
int _TimeBetweenReadings;
float _m1;
float _m2;
float _b1;
float _b2;
float _temperatureAverage;
float _measuredTemperature;
float _measuredTemperatureDeviation;
bool _pump;
unsigned long _lastTemperatureRead;
int _VoutAnalogSample;
int _VoutRAnalogSample;
float _VoutPreviousAnalogSample;
int _temperatureMeasurementsMarker;
int _rTemperatureMeasurementsMarker;
float _temperatureMeasurements[TEMPERATURE_AVERAGE_VALUE_I] = {TEMPERATURE_AVERATE_INIT_VALUES};
int _rTemperatureMeasurements[TEMPERATURE_AVERAGE_VALUE_I] = {TEMPERATURE_AVERATE_INIT_VALUES_I};
float GetMedian(int array[]);
float GetMedianAverage(int array[], int range);
float GetMode(float array[]);
};
#endif
/*
Temperature.h - Library for measuring temperature with a Temperature.
Created by João Lino, December 22, 2015.
Released into the public domain.
*/
#ifndef TEMPERATURE_h
#define TEMPERATURE_h
#include "Arduino.h"
#define DEBUG
#define CONSTANT_ADC_STEP_COUNT 1024.0
#define TEMPERATURE_AVERAGE_VALUE_I 50
#define TEMPERATURE_AVERAGE_VALUE_F 50.0
//#define TEMPERATURE_AVERATE_INIT_VALUES 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
#define TEMPERATURE_AVERATE_INIT_VALUES 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
#define TEMPERATURE_AVERATE_INIT_VALUES_I 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
#define TEMPERATURE_SETTING_MAX_VALUE 120
class Temperature
{
public:
// Temperature(Temperature_OUTPUT_PIN, Temperature_INPUT_PIN, Temperature_TIME_BETWEEN_READINGS, Temperature_DEFAULT_ADC_VMAX, Temperature_DEFAULT_VS, Temperature_DEFAULT_R1_RESISTENCE, Temperature_DEFAULT_LINE_RESISTENCE, Temperature_DEFAULT_OPERATION_RESISTENCE);
Temperature(char *name,
int OutputPin_SensorPower,
int InputPin_TemperatureReading,
int TimeBetweenReadings = 100);
void measure(boolean ln);
void measure1(boolean ln, boolean rline);
void safeHardwarePowerOff();
float getCurrentTemperature();
float getMeasuredTemperatureDeviation();
float setMeasuredTemperatureDeviation( float measuredTemperatureDeviation);
float setSampleDeviation( float sampleDeviation);
private:
char *_name;
int _OutputPin_SensorPower;
int _OutputPin_ThirdLinePower;
int _InputPin_TemperatureReading;
int _InputPin_ThirdLineReading;
int _TimeBetweenReadings;
float _ADCVmax;
float _Vs;
float _R1;
float _R2;
float __m;
float __b;
float _temperatureAverage;
float _measuredTemperature;
float _measuredTemperatureDeviation;
float _sampleDeviation;
unsigned long _lastTemperatureRead;
int _VoutAnalogSample;
int _VoutRAnalogSample;
float _VoutPreviousAnalogSample;
int _temperatureMeasurementsMarker;
int _rTemperatureMeasurementsMarker;
int _rLineMeasurementsMarker;
float _temperatureMeasurements[TEMPERATURE_AVERAGE_VALUE_I] = {TEMPERATURE_AVERATE_INIT_VALUES};
int _rTemperatureMeasurements[TEMPERATURE_AVERAGE_VALUE_I] = {TEMPERATURE_AVERATE_INIT_VALUES_I};
int _rLineMeasurements[TEMPERATURE_AVERAGE_VALUE_I] = {TEMPERATURE_AVERATE_INIT_VALUES_I};
float GetMedian(int array[]);
};
#endif
\ No newline at end of file
#ifndef __BREW
#define __BREW
void xSetupRotaryEncoder( eRotaryEncoderMode newMode, int newPosition, int newMaxPosition, int newMinPosition, int newSingleStep, int newMultiStep );
// ######################### START #########################
void xSafeHardwarePowerOff();
void xWelcomeUser();
// ######################### FUNCTIONS ########################
void runMenu();
void runSettingsSelection();
void runMaltSelection();
void runStageSelection();
void runBeerProfileSelection();
void runStartFromStageSelection_Processor( unsigned long *stageTime, int *stageTemperature, eCookingStages nextStage );
void runStartFromStageSelection();
void runMainMenuSelection();
void xCountTheTime( int temperatureRange, boolean bAverageUpDown );
bool isTimeLeft();
double ulWattToWindowTime( double ulAppliedWatts );
bool xRegulateTemperature( boolean bAverageUpDown );
void xPurgePump();
bool xRegulatePumpSpeed();
void xWarnClockEnded();
void xWarnCookEnded();
void xStageFirstRun( int stageTime, int stageTemperature, int stagePumpSpeed, eCookingStages stage );
void xSetupGlobalVariablesForStage(eCookingStages nextStage);
void xTransitionIntoStage(eCookingStages nextStage);
void xBasicStageOperation( int iStageTime, int iStageTemperature, int iStageTemperatureRange, eCookingStages nextStage, boolean bAverageUpDown );
void xManageMachineSystems();
// #################################################### Helpers ##################################################################
void startBrewing();
void stopBrewing();
void resetMenu( boolean requestRepaintPaint );
void backToStatus();
// #################################################### Set Variables ##################################################################
int getTimer( int initialValue, int defaultValue );
int getTimer( int initialValue );
int getTemperature(int initialValue);
int xSetGenericValue(int initialValue, int minimumValue, int maximumValue, char *valueName, char *unit);
int xSetTemperature( int initialValue );
int xSetFinalYield( int initialValue );
// ###################### Set Variables ##################################################
void xWaitForAction(String title, String message);
boolean gotButtonPress(int iPin);
#endif //__BREW
\ No newline at end of file
This diff is collapsed.
......@@ -8,8 +8,10 @@
#define CONFIG_h
// ######################### SETTINGS #########################
#define SETTING_CLEANING_TIME 1200 //1200
#define SETTING_CLEANING_TIME 1200 //1200
#define SETTING_CLEANING_TEMPERATURE 45 //45
#define SETTING_MACHINE_YIELD_CAPACITY_MIN 0
#define SETTING_MACHINE_YIELD_CAPACITY_MAX 50
// ++++++++++++++++++++++++ Heating Element Relay ++++++++++++++++++++++++
#define HEATING_ELEMENT_DEFAULT_WINDOW_SIZE 1000
......@@ -20,22 +22,24 @@
#define HEATING_ELEMENT_AC_FREQUENCY_HZ 50.0
// ++++++++++++++++++++++++ Temperature ++++++++++++++++++++++++
#define TEMPERATURE_MIN_VALUE 0
#define TEMPERATURE_MAX_VALUE 120
#define PT100_BASE_INPUT_PIN A4
#define PT100_BASE_OUTPUT_PIN 32
#define PT100_BASE_INPUT_R_PIN A7
#define PT100_BASE_OUTPUT_R_PIN 7
//#define PT100_BASE_INPUT_R_PIN A7
//#define PT100_BASE_OUTPUT_R_PIN 7
#define PT100_BASE_TIME_BETWEEN_READINGS 1
#define PT100_UP_INPUT_PIN A5
#define PT100_UP_OUTPUT_PIN 30
#define PT100_UP_INPUT_R_PIN A8
#define PT100_UP_OUTPUT_R_PIN 9
//#define PT100_UP_INPUT_R_PIN A8
//#define PT100_UP_OUTPUT_R_PIN 9
#define PT100_UP_TIME_BETWEEN_READINGS 1
#define PT100_DOWN_INPUT_PIN A6
#define PT100_DOWN_OUTPUT_PIN 31
#define PT100_DOWN_INPUT_R_PIN A9
#define PT100_DOWN_OUTPUT_R_PIN 8
//#define PT100_DOWN_INPUT_R_PIN A9
//#define PT100_DOWN_OUTPUT_R_PIN 8
#define PT100_DOWN_TIME_BETWEEN_READINGS 1
/*
#define PT100_BASE_DEFAULT_ADC_VMAX 1.1
#define PT100_BASE_DEFAULT_VS 5.0
#define PT100_BASE_DEFAULT_R1_RESISTENCE 605.2
......@@ -48,6 +52,7 @@
#define PT100_DOWN_DEFAULT_VS 5.0
#define PT100_DOWN_DEFAULT_R1_RESISTENCE 616.0
#define PT100_DOWN_DEFAULT_R2_RESISTENCE 611.0
*/
// ++++++++++++++++++++++++ Mixer ++++++++++++++++++++++++
//#define MIXER_PIN 12
......@@ -60,9 +65,11 @@
#define PUMP_PIN 6
#define PUMP_TEMPERATURE_MAX_OPERATION 90
#define PUMP_SPEED_STOP 0
#define PUMP_SPEED_STOP_MOSFET 255
#define PUMP_SPEED_SLOW 64
#define PUMP_SPEED_AVERAGE 128
#define PUMP_SPEED_FAST 192
#define PUMP_SPEED_MAX_MOSFET 0
#define PUMP_SPEED_MAX 255
// ++++++++++++++++++++++++ Rotary Encoder ++++++++++++++++++++++++
......@@ -75,11 +82,13 @@
// ++++++++++++++++++++++++ State Machine ++++++++++++++++++++++++
#define SETTING_WELCOME_TIMEOUT 100
#define SETTING_MAX_INACTIVITY_TIME 3000
#define MENU_SIZE_MAIN_MENU 12
#define MENU_SIZE_MAIN_MENU 13
#define MENU_SIZE_PROFILES_MENU 9
#define MENU_SIZE_STAGE_MENU 13
#define MENU_SIZE_MALT_MENU 4
#define MENU_SIZE_SETTINGS_MENU 5
#define MENU_SIZE_SETTINGS_MENU 6
// ++++++++++++++++++++++++ Serial Monotor ++++++++++++++++++++++++
#define SETTING_SERIAL_MONITOR_BAUD_RATE 9600
#define SETTING_SERIAL_MONITOR_WELCOME_MESSAGE "Let's start Brewing!"
......@@ -97,4 +106,4 @@
#define LCD_D6_PIN 6
#define LCD_D7_PIN 7
#endif
\ No newline at end of file
#endif
......@@ -5,7 +5,7 @@
*/
#ifndef DEBUG_h
#define DEBUB_h
#define DEBUG_h
// ######################### TEMPLATES #########################
template <class T> void debugPrintVar( char *name, const T& value );
......
This diff is collapsed.
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