/*
Opal Ice maker custom controller
large fonts
http://patorjk.com/software/taag/#p=display&h=1&v=1&c=c%2B%2B&f=Doom&t=%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Ice%20Machine
http://patorjk.com/software/taag/#p=display&h=1&v=1&c=c%2B%2B&f=Rectangles&t=%20%20%20%20%20%20%20%20Ice%20Machine
*/
// .-'''-. _..._
// ' _ \ .---. .-'_..._''.
// / /` '. \_________ _...._ | | .--. .' .' '.\ __.....__
// . | \ '\ |.' '-. | | |__| / .' .-'' '.
// | ' | '\ .'```'. '. | | .--.. ' / .-''"'-. `.
// \ \ / / \ | \ \ __ | | | || | / /________\ \
// `. ` ..' / | | | |.:--.'. | | | || | | |
// '-...-'` | \ / ./ | \ | | | | |. ' \ .-------------'
// | |\`'-.-' .' `" __ | | | | | | \ '. .\ '-.____...---.
// | | '-....-'` .'.''| | | | |__| '. `._____.-'/ `. .'
// .' '. / / | |_'---' `-.______ / `''-...... -'
// '-----------' \ \._,\ '/ `
// `--' `"
#define OLED
#define USE_HSV
#include "WS2812.h" // https://github.com/cpldcpu/light_ws2812/tree/master
//#include "OneButton.h"
#include "SSD1306Ascii.h"
#include "SSD1306AsciiAvrI2c.h"
#include <thermistor.h> // https://github.com/miguel5612/Arduino-ThermistorLibrary
//------------------------------------------------------------------
#define RST_PIN -1 // Define proper RST_PIN if required.
#define upPin 2
#define downPin 3
#define ledRingPin 4
#define binLedPin 5
#define uvPin 6
#define pumpPin 7
#define irPin 8
#define cleanPin 9
#define binPin 10
#define compressorPin 11
#define augerPin 12
#define fanPin 13
#define analogVoltagePin A0
#define touchPin A1
#define temp1Pin A2
#define temp2Pin A3
#define sdaPin A4
#define sclPin A5
#define waterLowPin A6
#define waterHighPin A7
//------------------------------------------------------------------
thermistor therm1(temp1Pin, 1); // Analog Pin which is connected to the 3950 temperature sensor, and 0 represents TEMP_SENSOR_0 (see configuration.h for more information).
thermistor therm2(temp2Pin, 1);
//------------------------------------------------------------------
#define I2C_ADDRESS 0x3c // 0X3C+SA0 - 0x3C or 0x3D
SSD1306AsciiAvrI2c oled;
uint8_t col[2]; // Columns for ADC values.
uint8_t columns;
uint8_t rows; // Rows per line.
//------------------------------------------------------------------
typedef enum BUTTON_STATUS
{
START,
STOP
} buttonStatus_t;
buttonStatus_t buttonStatus;
//------------------------------------------------------------------
typedef enum WATER_LEVEL
{
WATER_LOW,
WATER_MID,
WATER_FULL
} waterLevel_t;
waterLevel_t waterLevel;
//------------------------------------------------------------------
typedef enum ICE_STATUS
{
ICE_OFF,
ICE_STARTUP,
ICE_RUNNING,
ICE_SHUTDOWN,
ICE_STANDBYE,
ICE_CLEANING,
ICE_DEFROST,
ICE_ERROR
} iceStatus_t;
iceStatus_t iceStatus;
//------------------------------------------------------------------
typedef enum ERROR_STATUS
{
none,
LOW_WATER,
AUGER_FROZEN
} errorCode_t;
errorCode_t errorCode;
//------------------------------------------------------------------
typedef enum OLED_MENU
{
MAIN,
SETTINGS
} oledMenu_t;
oledMenu_t oledMenu;
//------------------------------------------------------------------
// macros from DateTime.h
/* Useful Constants */
#define SECS_PER_MIN (60UL)
#define SECS_PER_HOUR (3600UL)
#define SECS_PER_DAY (SECS_PER_HOUR * 24L)
/* Useful Macros for getting elapsed time */
#define numberOfSeconds(_time_) (_time_ % SECS_PER_MIN)
#define numberOfMinutes(_time_) ((_time_ / SECS_PER_MIN) % SECS_PER_MIN)
#define numberOfHours(_time_) (( _time_% SECS_PER_DAY) / SECS_PER_HOUR)
#define elapsedDays(_time_) ( _time_ / SECS_PER_DAY)
//------------------------------------------------------------------
//------------------------------------------------------------------
const int numReadings = 6;
int readIndex = 0; // the index of the current reading
int totalIr = 0; // the running total
int averageIrCountPerMin = 0; // the average
unsigned int irCounts[numReadings] = {0, 0, 0, 0, 0, 0};
bool irSensor = false;
unsigned int irCount = 0;
bool notIrSensor = true;
unsigned long prevIrCount = 0;
//------------------------------------------------------------------
//const int numReadings = 10;
int augerReadings[numReadings]; // the augerReadings from the analog input
int augerReadIndex = 0; // the index of the current reading
int augerTotal = 0; // the running augerTotal
int augerAverage = 0; // the augerAverage
int prevAugerAverage = 0; // the augerAverage
int compReadings[numReadings]; // the compReadings from the analog input
int compReadIndex = 0; // the index of the current reading
int compTotal = 0; // the running compTotal
int compAverage = 0; // the compAverage
int prevCompAverage = 0; // the compAverage
int cpuReadings[numReadings]; // the compReadings from the analog input
int cpuReadIndex = 0; // the index of the current reading
int cpuTotal = 0; // the running compTotal
int cpuAverage = 0; // the compAverage
//------------------------------------------------------------------
//TMP36 compTemp(temp1Pin, 4.56);
//TMP36 augerTemp(temp2Pin, 4.56);
float compF = 0.0;
float augerF = 0.0;
//------------------------------------------------------------------
#define LEDCount 16
WS2812 LED(LEDCount);
cRGB value;
cRGB valueOff;
int h = 0; //stores 0 to 614
byte steps = 50; //number of hues we skip in a 360 range per update
byte sat = 255;
byte val = 127;
long sleep = 100; //delays between update
//------------------------------------------------------------------
unsigned long currentMillis = 0;
unsigned long currentSec = 0;
unsigned long previousMillis = 0;
unsigned long prevLed = 0;
unsigned long prevInput = 0;
unsigned long startTime = 0;
unsigned long runTime = 0;
unsigned int pumpStartTime = 0;//seconds
unsigned int pumpRunTime = 0;//seconds
unsigned int cleaningStartTime = 0;//seconds
unsigned int buttonPushTime = 0;//seconds
unsigned int menuTimeout = 20;//seconds
unsigned int irStartTime = 0;//seconds
//------------------------------------------------------------------
unsigned int cleanStartTime = 0;//seconds
bool cleaningStart = false;
//------------------------------------------------------------------
bool binLeds = false;
bool pumpRunning = false;
bool compressorRunning = false;
bool augerRunning = false;
bool pumpStart = false;
bool fanRunning = false;
bool irBlocked = false;
bool triggerDisplay = false;
//------------------------------------------------------------------
// ----------------- USER SETTINGS -----------------
unsigned int binLedHigh = 200;
unsigned int binLedLow = 50;
unsigned int irBlockedTime = 10;//seconds
unsigned int cleanRunTime = 300; //seconds
unsigned int pumpWaterTimeout = 30;//seconds
unsigned int compressorHighTemp = 100;//F
unsigned int augerLowTemp = 40;// auger temp on startup to low
unsigned int augerHighTemp = 60;//f temp for defrost
unsigned int augerShutdownTemp = 50; // temp for shutdown to move to OFF
unsigned int startup2running = 45;//f
//------------------------------------------------------------------
#define fanON {digitalWrite(fanPin, false); fanRunning=true;} //relay
#define fanOFF {digitalWrite(fanPin, true); fanRunning=false;} //relay
#define compressorON {digitalWrite(compressorPin, false); compressorRunning=true;} //relay
#define compressorOFF {digitalWrite(compressorPin, true); compressorRunning=false;} //relay
#define augerON {digitalWrite(augerPin, false); augerRunning=true;} //relay
#define augerOFF {digitalWrite(augerPin, true); augerRunning=false;} //relay
#define pumpON {digitalWrite(pumpPin, false); pumpRunning=true;} //relay
#define pumpOFF {digitalWrite(pumpPin, true); pumpRunning=false;} //relay
#define uvON {digitalWrite(uvPin, true);} //mosfet
#define uvOFF {digitalWrite(uvPin, false);} //mosfet
#define binLED(s) { analogWrite(binLedPin,s); } //mosfet
//===================================================================================
// _____ _
// / ___| | |
// \ `--. ___ | |_ _ _ _ __
// `--. \ / _ \| __|| | | || '_ \
// /\__/ /| __/| |_ | |_| || |_) |
// \____/ \___| \__| \__,_|| .__/
// | |
// |_|
//===================================================================================
void setup() {
Serial.begin(115200);
Serial.println("setup start");
//----------------------------------------------------------------------
pinMode(upPin, INPUT_PULLUP);
pinMode(downPin, INPUT_PULLUP);
pinMode(touchPin, INPUT_PULLUP);
pinMode(cleanPin, INPUT_PULLUP);
pinMode(binPin, INPUT_PULLUP);
pinMode(analogVoltagePin, INPUT);
pinMode(waterLowPin, INPUT);
pinMode(waterHighPin, INPUT);
pinMode(irPin, INPUT_PULLUP);
pinMode(compressorPin, OUTPUT);
pinMode(augerPin, OUTPUT);
pinMode(fanPin, OUTPUT);
pinMode(pumpPin, OUTPUT);
pinMode(binLedPin, OUTPUT);
pinMode(uvPin, OUTPUT);
//----------------------------------------------------------------------
compressorON;
augerON;
fanON;
pumpON;
binLED(255);
uvON;
delay(1000);
compressorOFF;
augerOFF;
fanOFF;
pumpOFF;
binLED(0);
uvOFF;
//----------------------------------------------------------------------
oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);
// Call oled.setI2cClock(frequency) to change from the default frequency.
oled.setFont(System5x7);
//oled.setFont(X11fixed7x14B);
oled.set2X();
uint32_t m = micros();
oled.clear();
oled.println(" OPAL Ice");
oled.set1X();
oled.println("");
oled.println("uploaded:");
oled.println(__TIME__);
oled.println(__DATE__);
//----------------------------------------------------------------------
LED.setOutput(ledRingPin);
LED.setColorOrderRGB(); // Uncomment for RGB color order
//LED.setColorOrderBRG(); // Uncomment for BRG color order
//LED.setColorOrderGRB(); // Uncomment for GRB color order (Default; will be used if none other is defined.)
valueOff.b = 0; valueOff.g = 0; valueOff.r = 0;
value.b = 0; value.g = 0; value.r = 255; // RGB Value -> Red
for (int i = 0; i < LEDCount; i++) {
LED.set_crgb_at(i, value);
LED.sync();// Sends the data to the LEDs
delay(50);
}
value.b = 0; value.g = 255; value.r = 0; // RGB Value -> Red
for (int i = 0; i < LEDCount; i++) {
LED.set_crgb_at(i, value);
LED.sync();// Sends the data to the LEDs
delay(50);
}
value.b = 255; value.g = 0; value.r = 0; // RGB Value -> Red
for (int i = 0; i < LEDCount; i++) {
LED.set_crgb_at(i, value);
LED.sync();// Sends the data to the LEDs
delay(50);
}
for (int i = 0; i < LEDCount; i++) {
LED.set_crgb_at(i, valueOff);
LED.sync();// Sends the data to the LEDs
delay(50);
}
//----------------------------------------------------------------------
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
augerReadings[thisReading] = 0;
}
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
compReadings[thisReading] = 0;
}
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
cpuReadings[thisReading] = 0;
}
delay(1000);
Serial.println("setup complete");
}
//===================================================================================
// _ _____ _____ ______
// | | | _ || _ || ___ \
// | | | | | || | | || |_/ /
// | | | | | || | | || __/
// | |____\ \_/ /\ \_/ /| |
// \_____/ \___/ \___/ \_|
//
//
//===================================================================================
void loop() {
currentMillis = millis();
currentSec = currentMillis / 1000;
bool btn1State = !digitalRead(touchPin);
bool btn2State = !digitalRead(upPin);
bool btn3State = !digitalRead(downPin);
bool btn4State = !digitalRead(cleanPin);
if (btn1State || btn2State || btn3State || btn4State) {
Serial.print("touch:");
Serial.print(btn1State); Serial.print("\t");
Serial.print("up:");
Serial.print(btn2State); Serial.print("\t");
Serial.print("down:");
Serial.print(btn3State); Serial.print("\t");
Serial.print("clean:");
Serial.print(btn4State); Serial.println("\t");
}
//------------------------------------------------------------------
if (currentMillis - prevInput > 500) {
checkWaterLevel();
getTemp();
if (iceStatus == ICE_ERROR) {
ledSolid(10, 0, 0);
} else if (buttonStatus == STOP) {
ledSolid(0, 0, 5);
} else {
ledSolid(0, 5, 0);
}
prevInput = currentMillis;
if (triggerDisplay) {
oledDisplay();
triggerDisplay = false;
}
//serialPrint();
}
//------------------------------------------------------------------
irSensor = digitalRead(irPin);
if (irSensor) {
if (notIrSensor) {
irCount++;
notIrSensor = false;
irStartTime = currentSec;
}
if ((currentSec - irStartTime) > irBlockedTime && !irBlocked) {
irBlocked = true;
}
} else {
notIrSensor = true;
if (irBlocked) {
irBlocked = false;
}
}
if (currentMillis - prevIrCount > 10000) {
IRcounting();
prevIrCount = currentMillis;
irCount = 0;
}
//------------------------------------------------------------------
if (buttonStatus == START) {
runTime = currentMillis - startTime;
}
//------------------------------------------------------------------
switch (iceStatus) {
case ICE_OFF: //off
fanOFF;
pumpOFF;
runAuger(false);
runCompressor(false);
binLED(0);
uvOFF;
break;
//-------------------------
case ICE_STARTUP: //
runFan();
if (!(waterLevel == WATER_FULL)) {
} else {
if (augerAverage < augerLowTemp) {
iceStatus = ICE_DEFROST;
} else {
uvON;
runAuger(true);
runCompressor(true);
if (augerAverage < startup2running) {
iceStatus = ICE_RUNNING;
}
}
}
break;
//-------------------------
case ICE_RUNNING: //
if (!irBlocked) {
runFan();
runAuger(true);
runCompressor(true);
uvON;
} else {
iceStatus = ICE_STANDBYE;
}
break;
//-------------------------
case ICE_SHUTDOWN:
uvOFF;
runCompressor(false);
runAuger(false);
runFan();
if (augerAverage > augerShutdownTemp) {
iceStatus = ICE_OFF;
}
break;
//-------------------------
case ICE_STANDBYE:
if (augerAverage < augerHighTemp) {
runFan();
runAuger(true);
runCompressor(false);
} else {
//runFan();
runAuger(false);
runCompressor(false);
}
if (!irBlocked) {
iceStatus = ICE_STARTUP;
}
break;
//-------------------------
case ICE_DEFROST:
runCompressor(false);
runAuger(false);
runFan();
break;
//-------------------------
case ICE_CLEANING:
runCompressor(false);
if (!cleaningStart) {
cleaningStartTime = (currentSec);
cleaningStart = true;
}
runFan();
runAuger(true);
break;
//-------------------------
case ICE_ERROR:
runFan();
pumpOFF;
runAuger(false);
runCompressor(false);
binLED(0);
break;
default:
break;
}
//------------------------------------------------------------------
if (iceStatus == ICE_RUNNING || iceStatus == ICE_STARTUP || iceStatus == ICE_CLEANING) {
switch (waterLevel) {
case WATER_LOW:
if (!pumpStart) {
pumpStartTime = currentSec;
pumpStart = true;
}
pumpRunTime = (currentSec) - pumpStartTime;
pumpON;
if (pumpRunTime > pumpWaterTimeout) {
iceStatus = ICE_ERROR;
errorCode = LOW_WATER;
}
break;
case WATER_MID:
pumpRunTime = (currentSec) - pumpStartTime;
break;
case WATER_FULL:
if (pumpRunning) {
pumpRunTime = (currentSec) - pumpStartTime;
}
pumpStart = false;
if (iceStatus == ICE_CLEANING) {
pumpON;
} else {
pumpOFF;
}
break;
}
}
//------------------------------------------------------------------
}//end of loop
//===================================================================================
// ______ _ _
// | ___| | | (_)
// | |_ _ _ _ __ ___ | |_ _ ___ _ __ ___
// | _|| | | || '_ \ / __|| __|| | / _ \ | '_ \ / __|
// | | | |_| || | | || (__ | |_ | || (_) || | | |\__ \
// \_| \__,_||_| |_| \___| \__||_| \___/ |_| |_||___/
//
//
//===================================================================================
//===================================================================================
void checkButtons() {
bool btn1State = !digitalRead(touchPin);
bool btn2State = !digitalRead(upPin);
bool btn3State = !digitalRead(downPin);
bool btn4State = !digitalRead(cleanPin);
if (btn1State || btn2State || btn3State || btn4State) {
Serial.print("touch:");
Serial.print(btn1State); Serial.print("\t");
Serial.print("up:");
Serial.print(btn2State); Serial.print("\t");
Serial.print("down:");
Serial.print(btn3State); Serial.print("\t");
Serial.print("clean:");
Serial.print(btn4State); Serial.println("\t");
}
}
//===================================================================================
// _____
// | | ___ _____ ___ ___ ___ ___ ___ ___ ___
// | --|| . || || . || _|| -_||_ -||_ -|| . || _|
// |_____||___||_|_|_|| _||_| |___||___||___||___||_|
// |_|
//===================================================================================
void runCompressor(bool STATUS) {
if (STATUS && fanRunning && compF < compressorHighTemp ) {
compressorON;
} else {
compressorOFF;
}
}
//===================================================================================
//
// _____
// | _ | _ _ ___ ___ ___
// | || | || . || -_|| _|
// |__|__||___||_ ||___||_|
// |___|
//===================================================================================
void runAuger(bool STATUS) {
if (STATUS) {
if (iceStatus == ICE_STARTUP) {
if (augerF < augerLowTemp) {
iceStatus = ICE_ERROR;
errorCode = AUGER_FROZEN;
}
} else {
augerON;
}
} else {
augerOFF;
}
}
//===================================================================================
//
// _____
// | __| ___ ___
// | __|| .'|| |
// |__| |__,||_|_|
//
//===================================================================================
void runFan() {
if (compressorRunning || augerRunning) {
fanON;
} else if (compF > 90) {
fanON;
} else {
fanOFF;
}
}
//===================================================================================
//
// _____ _
// |_ _|___ _____ ___ ___ ___ ___ | |_ _ _ ___ ___
// | | | -_|| || . || -_|| _|| .'|| _|| | || _|| -_|
// |_| |___||_|_|_|| _||___||_| |__,||_| |___||_| |___|
// |_|
//===================================================================================
void getTemp() {
int analog5v = analogRead(analogVoltagePin);
//int analog1 = analogRead(temp1Pin);
//int analog2 = analogRead(temp2Pin);
int analog1 = therm1.analog2temp();
int analog2 = therm2.analog2temp();
//Serial.print("therm1:"); Serial.print(analog1); Serial.print("\t");
//Serial.print("therm2:"); Serial.print(analog2); Serial.println("\t");
//Serial.print("analog5v="); Serial.print(analog5v); Serial.print("\t");
float voltage5v = (analog5v / 1024.0) * 5.0000;
//Serial.print("voltage5v="); Serial.println(voltage5v);
//float voltage1 = (analog1 * voltage5v) / 1024.0;
//float voltage2 = (analog2 * voltage5v) / 1024.0;
/*
float temp1C = (voltage1 - .5) * 100;
float temp2C = (voltage2 - .5) * 100;
float temp1F = (temp1C * (9.0 / 5.0)) + 32.0;
float temp2F = (temp2C * (9.0 / 5.0)) + 32.0;
compF = temp1F;
augerF = temp2F;
*/
compF = analog1;
augerF = analog2;
augerTotal = augerTotal - augerReadings[augerReadIndex];
augerReadings[augerReadIndex] = augerF;
augerTotal = augerTotal + augerReadings[augerReadIndex];
augerReadIndex = augerReadIndex + 1;
compTotal = compTotal - compReadings[compReadIndex];
compReadings[compReadIndex] = compF;
compTotal = compTotal + compReadings[compReadIndex];
compReadIndex = compReadIndex + 1;
cpuTotal = cpuTotal - cpuReadings[cpuReadIndex];
cpuReadings[cpuReadIndex] = GetTemp();
cpuTotal = cpuTotal + cpuReadings[cpuReadIndex];
cpuReadIndex = cpuReadIndex + 1;
if (augerReadIndex >= numReadings) {
augerReadIndex = 0;
}
if (compReadIndex >= numReadings) {
compReadIndex = 0;
}
if (cpuReadIndex >= numReadings) {
cpuReadIndex = 0;
}
cpuAverage = cpuTotal / numReadings;
augerAverage = augerTotal / numReadings;
compAverage = compTotal / numReadings;
if (compAverage != prevCompAverage) {
triggerDisplay = true;
prevCompAverage = compAverage;
}
if (augerAverage != prevAugerAverage) {
triggerDisplay = true;
prevAugerAverage = augerAverage;
}
}
//===================================================================================
//
// _____ _ _
// | __ | _ _ | |_ | |_ ___ ___
// | __ -|| | || _|| _|| . || |
// |_____||___||_| |_| |___||_|_|
//
//===================================================================================
void ClickFunctionUp() {
buttonPushTime = currentSec;
}
//===================================================================================
void doubleclickUp() {
buttonPushTime = currentSec;
}
//===================================================================================
void ClickFunctionDown() {
buttonPushTime = currentSec;
}
//===================================================================================
void doubleclickDown() {
buttonPushTime = currentSec;
}
//===================================================================================
void ClickFunction() {
if (buttonStatus == STOP) {
ledSingle(0, 200, 0, 100);
buttonStatus = START;
iceStatus = ICE_STARTUP;
startTime = currentMillis;
} else {
ledSingle(0, 0, 200, 100);
buttonStatus = STOP;
iceStatus = ICE_SHUTDOWN;
}
}
//===================================================================================
void doubleclick() {
static int m = LOW;
// reverse the LED
m = !m;
ledSingle(0, 0, 255, 100);
errorCode = none;
iceStatus = ICE_OFF;
buttonStatus = STOP;
cleaningStart = false;
} // doubleclick
//===================================================================================
void PressStartFunction() {
}
//===================================================================================
void LongPressStartFunction() {
ledSingle2(200, 0, 0, 100);
;
}
//===================================================================================
void DuringLongPressFunction() {
}
//===================================================================================
void LongPressStopFunction() {
}
//===================================================================================
//
// _ _ _ _ __ _
// | | | | ___ | |_ ___ ___ | | ___ _ _ ___ | |
// | | | || .'|| _|| -_|| _| | |__ | -_|| | || -_|| |
// |_____||__,||_| |___||_| |_____||___| \_/ |___||_|
//
//===================================================================================
void checkWaterLevel() {
int waterLowA = analogRead(waterLowPin);
int waterFullA = analogRead(waterHighPin);
if (waterLowA < 500) waterLevel = WATER_LOW;
if (waterFullA < 500) waterLevel = WATER_FULL;
if (waterLowA > 500 && waterFullA > 500) waterLevel = WATER_MID;
}
//===================================================================================
//
// _ _
// ___ | | ___ ___ ___ |_| ___ ___
// | _|| || -_|| .'|| || || || . |
// |___||_||___||__,||_|_||_||_|_||_ |
// |___|
//===================================================================================
void runClean() {
pumpON;
compressorOFF;
augerON;
fanON;
}
//===================================================================================
//
// _ _____
// |_| ___ | __| ___ ___ ___ ___ ___
// | || _| |__ || -_|| ||_ -|| . || _|
// |_||_| |_____||___||_|_||___||___||_|
//
//===================================================================================
void IRcounting() {
totalIr = totalIr - irCounts[readIndex];// subtract the last reading:
irCounts[readIndex] = irCount;// read from the sensor:
totalIr = totalIr + irCounts[readIndex];// add the reading to the totalIr:
readIndex = readIndex + 1;// advance to the next position in the array:
if (readIndex >= numReadings) {// if we're at the end of the array...
// ...wrap around to the beginning:
readIndex = 0;
}
averageIrCountPerMin = totalIr / numReadings; // calculate the averageIrCountPerMin:
}
//===================================================================================
//
// __ _____ ____
// | | | __|| \
// | |__ | __|| | |
// |_____||_____||____/
//
//===================================================================================
void ledSingle(int r, int g, int b, int delayTime) {
sleep = delayTime;
value.b = b; value.g = g; value.r = r;
for (int i = 0; i < LEDCount; i++) {
LED.set_crgb_at(i, value);
LED.set_crgb_at(i - 1, valueOff);
if (i == 0) {
LED.set_crgb_at(LEDCount - 1, valueOff);
}
LED.sync();// Sends the data to the LEDs
delay(sleep);
}
}
//===================================================================================
void ledSingle2(int r, int g, int b, int delayTime) {
sleep = delayTime;
value.b = b; value.g = g; value.r = r;
for (int i = LEDCount; i >= 0; i--) {
LED.set_crgb_at(i, value);
LED.set_crgb_at(i + 1, valueOff);
if (i == 0) {
LED.set_crgb_at(LEDCount - 1, valueOff);
}
LED.sync();// Sends the data to the LEDs
delay(sleep);
}
}
//===================================================================================
void ledBounce(int r, int g, int b, int delayTime) {
sleep = delayTime;
value.b = b; value.g = g; value.r = r;
for (int i = 0; i < LEDCount; i++) {
LED.set_crgb_at(i, value);
LED.set_crgb_at(i - 1, valueOff);
if (i == 0) {
LED.set_crgb_at(LEDCount - 1, valueOff);
}
LED.sync();// Sends the data to the LEDs
delay(sleep);
}
for (int i = LEDCount; i >= 0; i--) {
LED.set_crgb_at(i, value);
LED.set_crgb_at(i + 1, valueOff);
if (i == 0) {
LED.set_crgb_at(LEDCount - 1, valueOff);
}
LED.sync();// Sends the data to the LEDs
delay(sleep);
}
}
//===================================================================================
void Cycle() {
value.SetHSV(h, sat, val);
h += steps;
if (h > 360) {
h %= 360;
}
}
//===================================================================================
void blinky() {
value.b = 255; value.g = 0; value.r = 0; // RGB Value -> Blue
LED.set_crgb_at(0, value); // Set value at LED found at index 0
LED.sync(); // Sends the value to the LED
delay(500); // Wait 500 ms
value.b = 0; value.g = 0; value.r = 255; // RGB Value -> Red
LED.set_crgb_at(0, value); // Set value at LED found at index 0
LED.sync(); // Sends the value to the LED
delay(500); // Wait 500 ms
}
//===================================================================================
void ledSolid(int r, int g, int b) {
value.b = b; value.g = g; value.r = r;
for (int i = 0; i < LEDCount; i++) {
LED.set_crgb_at(i, value);
}
LED.sync();// Sends the data to the LEDs
}
//===================================================================================
//
// _____ _ _ _____ _ _
// | __| ___ ___ |_| ___ | | | _ | ___ |_| ___ | |_
// |__ || -_|| _|| || .'|| | | __|| _|| || || _|
// |_____||___||_| |_||__,||_| |__| |_| |_||_|_||_|
//
//===================================================================================
void serialPrint() {
Serial.print("IR count:");
for (int i = 0; i < numReadings; i++) {
Serial.print(irCounts[i]);
Serial.print(", ");
}
Serial.print(" avg="); Serial.println(averageIrCountPerMin);
Serial.print("waterLevel:");
if (waterLevel == WATER_LOW) Serial.print("LOW");
if (waterLevel == WATER_MID) Serial.print("MID");
if (waterLevel == WATER_FULL) Serial.print("FULL");
if (pumpRunning)Serial.print("\tpump:ON"); else Serial.print("\tpump:OFF");
Serial.print("\tpumpRT="); Serial.println(pumpRunTime);
Serial.print("auger="); Serial.print(augerF, 1); Serial.print("F");
Serial.print("\t comp="); Serial.print(compF, 1); Serial.print("F");
Serial.print("\t internal="); Serial.print(GetTemp(), 1); Serial.println("F");
time(runTime / 1000);
Serial.println(" ");
}
//===================================================================================
//
// _ _ _ _____ _
// |_| ___ | |_ ___ ___ ___ ___ | | |_ _|___ _____ ___ ___ ___ ___ | |_ _ _ ___ ___
// | || || _|| -_|| _|| || .'|| | | | | -_|| || . || -_|| _|| .'|| _|| | || _|| -_|
// |_||_|_||_| |___||_| |_|_||__,||_| |_| |___||_|_|_|| _||___||_| |__,||_| |___||_| |___|
// |_| |_|
//===================================================================================
double GetTemp(void) { //328p internal temp
unsigned int wADC;
double t;
double tf;
// The internal temperature has to be used
// with the internal reference of 1.1V.
// Channel 8 can not be selected with
// the analogRead function yet.
ADMUX = (_BV(REFS1) | _BV(REFS0) | _BV(MUX3));// Set the internal reference and mux.
ADCSRA |= _BV(ADEN); // enable the ADC
delay(20); // wait for voltages to become stable.
ADCSRA |= _BV(ADSC); // Start the ADC
while (bit_is_set(ADCSRA, ADSC)); // Detect end-of-conversion
wADC = ADCW;// Reading register "ADCW" takes care of how to read ADCL and ADCH.
t = (wADC - 324.31 ) / 1.22;// The offset of 324.31 could be wrong. It is just an indication.
tf = (t * (9.0 / 5.0)) + 32.0;
//return (t);// The returned temperature is in degrees Celcius.
return (tf);// The returned temperature is in degrees F.
}
//===================================================================================
//
// _ _ _
// | |_ |_| _____ ___ ___ ___ ___ _ _ ___ ___ ___ |_| ___ ___
// | _|| || || -_| | _|| . || || | || -_|| _||_ -|| || . || |
// |_| |_||_|_|_||___| |___||___||_|_| \_/ |___||_| |___||_||___||_|_|
//
//===================================================================================
void time(long val) {
int days = elapsedDays(val);
int hours = numberOfHours(val);
int minutes = numberOfMinutes(val);
int seconds = numberOfSeconds(val);
// digital clock display of current time
Serial.print(days, DEC);
printDigits(hours);
printDigits(minutes);
printDigits(seconds);
Serial.println();
}
//===================================================================================
void printDigits(byte digits) {
// utility function for digital clock display: prints colon and leading 0
Serial.print(":");
if (digits < 10)
Serial.print('0');
Serial.print(digits, DEC);
}
//===================================================================================
//
// _____ __ _____ ____ ____ _ _
// | || | | __|| \ | \ |_| ___ ___ | | ___ _ _
// | | || |__ | __|| | | | | || ||_ -|| . || || .'|| | |
// |_____||_____||_____||____/ |____/ |_||___|| _||_||__,||_ |
// |_| |___|
//===================================================================================
/*
Adafruit5x7
cp437font8x8
fixed_bold10x15
fixednums15x31
fixednums7x15
fixednums8x16
font5x7
font8x8
lcd5x7
lcdnums12x16
lcdnums14x24
newbasic3x5
Stang5x7
System5x7
Wendy3x5
X11fixed7x14
X11fixed7x14B
ZevvPeep8x16
*/
void oledDisplay() {
oled.clear();
//oled.set2X();
//oled.setFont(fixed_bold10x15);
oled.set1X();
if (currentSec - menuTimeout > buttonPushTime) {
switch (oledMenu) {
case MAIN:
if (iceStatus == ICE_OFF) {
//oled.setCursor(0, 0);
oled.print("status:"); oled.set2X(); oled.println(" Off"); oled.set1X();
oled.print("comp: "); oled.print(compAverage); oled.print(char(128)); oled.println("f");
oled.print("auger:"); oled.print(augerAverage); oled.print(char(128)); oled.println("f");
oled.print("cpu:"); oled.print(cpuAverage); oled.print(char(128)); oled.println("f");
//oled.print("ir count: "); oled.print(averageIrCountPerMin); oled.println("ppm");
}
if (iceStatus == ICE_STARTUP) {
oled.set1X();
oled.print("status:");
oled.set2X();
oled.println(" Startup");
oled.set1X();
oled.print("auger: "); oled.print(augerAverage); oled.println("f" );
}
if (iceStatus == ICE_RUNNING) {
oled.set1X();
oled.print("status:");
oled.set2X();
oled.println(" Running");
}
if (iceStatus == ICE_SHUTDOWN) {
oled.set1X();
oled.print("status:");
oled.set2X();
oled.println(" shutdown");
}
if (iceStatus == ICE_STANDBYE) {
oled.set1X();
oled.print("status:");
oled.set2X();
oled.println(" standbye");
}
if (iceStatus == ICE_CLEANING) {
oled.set1X();
oled.print("status:");
oled.set2X();
oled.println(" cleaning");
}
if (iceStatus == ICE_DEFROST) {
oled.set1X();
oled.print("status:");
oled.set2X();
oled.println(" defrosting");
oled.set1X();
oled.print("auger: "); oled.print(augerAverage); oled.println("f" );
}
if (iceStatus == ICE_ERROR) {
oled.set1X();
oled.print("status:");
oled.set2X();
oled.println(" ERROR");
oled.set1X();
if (errorCode == LOW_WATER) {
oled.println(" LOW WATER");
}
if (errorCode == AUGER_FROZEN) {
oled.println(" Auger To Cold");
}
}
break;
}
} else { /*setup menu*/}
}
//===================================================================================