// Fog Storm Prototype Board_20231214
// NK Pragmatic Innovations LLC Copyright 2023
// 5V Nano Controller (ATmega328) on Custom Board: DMX INTERFACE_20231127
// DMXSerial library will disable serial communication functionality
// ***NOTE: Jumper must be removed from Rx terminal to load programs
// 1kOHM resistors for Pt1000 RTD
//DMX CHANNEL 1 FOR FOG EFFECT CONTROL
//DMX CHANNEL 2 FOR SOLUTION PUMP CONTROL
//OUT1 = Fog Heater SCR PWM control
//OUT2 = Fog Pump Relay_Channel 2
//5Vdc power out for opticoupler and AC driver excite (IF VARIABLE PUMP SPEED)
//#include <DMXSerial.h> //Comment out for DEBUG
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//DISPLAY INFORMATION
#define NUMFLAKES 5 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
#define XPOS 0 // Indexes into the 'icons' array in function below
#define YPOS 1
#define DELTAY 2
static const unsigned char PROGMEM SF_bmp[] =
{0x00, 0x00, 0x01, 0x80, 0x07, 0xe0, 0x09, 0x90, 0x69, 0x96, 0x19, 0x98, 0x3d, 0xbc, 0x03, 0xc0,
0x03, 0xc0, 0x3f, 0xfc, 0x19, 0x98, 0x69, 0x96, 0x09, 0x90, 0x07, 0xe0, 0x01, 0x80, 0x00, 0x00};
// GSE Logo BitMap, 128x64px
const unsigned char GSE_bmp [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0xf8, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xe3, 0xf0, 0x7f, 0xff, 0xff, 0x83, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x8f, 0xfc, 0x1f, 0xff, 0xfe, 0x00, 0xf0, 0x1f, 0x80, 0x1c, 0x00, 0x7f, 0x00, 0x3c, 0x0f,
0xff, 0x82, 0x7f, 0x0f, 0xff, 0xfc, 0x00, 0x30, 0x1f, 0x00, 0x0c, 0x00, 0x1f, 0x00, 0x3c, 0x0f,
0xff, 0x00, 0x0e, 0x03, 0xdf, 0xf8, 0x00, 0x30, 0x1e, 0x00, 0x0c, 0x00, 0x1f, 0x00, 0x3c, 0x0f,
0xfa, 0x01, 0x0e, 0x01, 0xff, 0xf8, 0x00, 0x10, 0x1e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x3c, 0x0f,
0xfe, 0x00, 0x8f, 0x00, 0xff, 0xf0, 0x18, 0x10, 0x1c, 0x06, 0x00, 0x0c, 0x0e, 0x00, 0x3c, 0x0f,
0xfc, 0x18, 0x93, 0x00, 0xe1, 0xf0, 0x18, 0x00, 0x1c, 0x06, 0x00, 0x0c, 0x0e, 0x00, 0x3c, 0x0f,
0xf8, 0x11, 0xbf, 0x40, 0x7c, 0xf0, 0x18, 0x00, 0x1c, 0x06, 0x00, 0x0c, 0x0e, 0x00, 0x3c, 0x0f,
0xf0, 0x01, 0xff, 0x00, 0x3f, 0xf0, 0x18, 0x00, 0x1c, 0x06, 0x00, 0x0c, 0x0e, 0x00, 0x1c, 0x0f,
0xf0, 0x00, 0x87, 0x80, 0x39, 0x30, 0x18, 0x00, 0x1c, 0x06, 0x00, 0x0c, 0x0e, 0x00, 0x1c, 0x0f,
0xe0, 0x00, 0x00, 0x4b, 0x36, 0x30, 0x1f, 0xf0, 0x1c, 0x06, 0x00, 0x00, 0x0e, 0x00, 0x1c, 0x0f,
0xe0, 0x00, 0x02, 0x0e, 0x1e, 0x30, 0x1f, 0xf0, 0x1c, 0x06, 0x00, 0x00, 0x1e, 0x08, 0x1c, 0x0f,
0xe0, 0x07, 0x80, 0x00, 0x1e, 0x70, 0x10, 0x00, 0x1c, 0x06, 0x00, 0x00, 0x3c, 0x08, 0x1c, 0x0f,
0xe0, 0x0f, 0xc8, 0x00, 0x1c, 0x70, 0x00, 0x00, 0x1c, 0x06, 0x00, 0x00, 0x0c, 0x08, 0x1c, 0x0f,
0xe0, 0x07, 0xf8, 0x80, 0x08, 0xf0, 0x00, 0x00, 0x1c, 0x06, 0x00, 0x00, 0x0c, 0x0c, 0x1c, 0x0f,
0xe7, 0x7f, 0xfe, 0x00, 0x01, 0xf0, 0x10, 0x00, 0x1c, 0x06, 0x00, 0x0c, 0x04, 0x0c, 0x0c, 0x0f,
0xe7, 0x7f, 0xff, 0x00, 0x03, 0xf0, 0x18, 0x00, 0x1c, 0x06, 0x00, 0x0c, 0x04, 0x00, 0x0c, 0x0f,
0xf1, 0xff, 0xff, 0x80, 0x07, 0xf0, 0x18, 0x00, 0x1c, 0x06, 0x00, 0x0c, 0x04, 0x00, 0x0c, 0x0f,
0xf9, 0xdf, 0xff, 0x80, 0x0f, 0xf0, 0x18, 0x00, 0x1c, 0x06, 0x00, 0x0c, 0x04, 0x00, 0x0c, 0x0f,
0xfd, 0xdf, 0xff, 0x80, 0x1f, 0xf0, 0x18, 0x00, 0x1c, 0x06, 0x00, 0x0c, 0x00, 0x00, 0x0c, 0x0f,
0xfd, 0xff, 0xff, 0xc0, 0x1f, 0xf0, 0x18, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00,
0xff, 0x9f, 0xff, 0xc3, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x04, 0x00,
0xff, 0x07, 0xff, 0xe7, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x0c, 0x04, 0x00,
0xff, 0x01, 0xff, 0xff, 0x3f, 0xfc, 0x00, 0x00, 0x01, 0x00, 0x0c, 0x00, 0x08, 0x0c, 0x04, 0x00,
0xfe, 0x00, 0xff, 0xff, 0x3f, 0xfe, 0x00, 0x00, 0x03, 0x80, 0x1c, 0x00, 0x18, 0x0c, 0x04, 0x00,
0xfe, 0x00, 0x3f, 0xff, 0x7f, 0xff, 0x0f, 0xff, 0xff, 0xe0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x00, 0x0f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x80, 0x0f, 0xff, 0xff, 0xf8, 0x61, 0x83, 0x19, 0xce, 0x7e, 0x08, 0x21, 0x06, 0x10, 0x21,
0xff, 0xc0, 0x0f, 0xff, 0xff, 0xf8, 0x60, 0x06, 0x09, 0x86, 0x7e, 0x08, 0x61, 0x04, 0x08, 0x20,
0xff, 0xc0, 0x1f, 0xff, 0xff, 0xf8, 0x60, 0x04, 0x79, 0x86, 0x7e, 0x08, 0x61, 0x04, 0xfc, 0xe1,
0xff, 0xe0, 0x7f, 0xff, 0xff, 0xf8, 0x01, 0x04, 0x79, 0x82, 0x7e, 0x08, 0x61, 0x04, 0xfc, 0xf0,
0xff, 0xe1, 0xff, 0xff, 0xff, 0xf8, 0x07, 0x06, 0x09, 0x00, 0x1e, 0x09, 0xe7, 0x04, 0x0c, 0xe4,
0xff, 0xf3, 0xff, 0xff, 0xff, 0xf8, 0x67, 0x82, 0x08, 0x30, 0x0e, 0x09, 0xe7, 0x06, 0x1c, 0xe0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// FOR DEGUGGING USE ONLY ###########################
#define DEBUG 0 //Turn on and off serial print data for debugging 1=ON, 0=OFF
#if DEBUG == 1
#define debug(x) Serial.print(x)
#define debugln(x) Serial.println(x)
#else
#define debug(x)
#define debugln(x)
#endif
#define RX_STATUS_PIN 1 //status LED
#define RX 0 //recieve serial
#define OUT1 3 // PWM OUTPUT 1
#define OUT2 5 // PWM OUTPUT 2
#define OUT3 6 // PWM OUTPUT 3
#define OUT4 9 // PWM OUTPUT 4
#define OUT5 10 // PWM OUTPUT 5
#define OUT6 11 // PWM OUTPUT 6
#define Vsens 13 // Vref for RTD
#define Menu_BTN A0 // Menu Button 1 READ
#define Up_BTN A1 // Up Button 2 READ
#define Dwn_BTN A2 // Down Button 3 READ
#define Ent_BTN A3 // Enter Button 4 READ
#define RTD1 A6 // Vin from RTD1
#define RTD2 A7 // Vin from RTD2
// A3 is SCL for I2C
// A4 is SDA for I2C
int ChSet=0; //Intial channel number
const int Dmxchannels=2; //the number of channels needed to control
int DMXvalue=0;
int DMXreading[2]; //match array to number of channels
int CH1val=0;
int CH2val=0;
const long fogtime=30000; //length of fog duty cycle_ (Default 30000)
const long fogstep1=7500;
const long fogstep2=15000;
const long fogstep3=22500;
const long DEMOtime=60000; //length of DEMO duty cycle_ (Default 60000)
const long DEMOstep=5000;
bool state = false; // state of switch or fog timer function
//variables for RTD measurement
const int Vin = 1023; // fine tune of suppy voltage reading 5.0 = 1023
const int R1 = 1000; // resistance of R1 in voltage divider
const int NumS = 25; // number of temperature samples
int samples[NumS]; //container for average
int ReadIndex = 0; //index of current reading
float Vout = 0; // voltage output from voltage divider (0-1023)
float runtotal = 0; //running total
float Vavg = 0; // average voltage reading
float R21; // calculated resistance of RTD 1
float T =0; // calculated Temp. C
// variables for Proportional control
const int setpoint = 230; // Desired temp setting in C_ (Default 225)
const int min_control = 25; // Bottom of control band, deg C below setpoint
const int minT=185; //Minimum temp to allow solution pump_ (Default 160)
const int Tc = 50; // total cyle Time in ms
float duty_on; // calculated on time
float duty_off; // calculated off time
float error = 0;
unsigned long currentMillis;
unsigned long prevMillis=0; //start at end of cycle
unsigned long counter = 0;
unsigned long currentMillisP;//pump current timer
unsigned long prevMillisP=0; //pump prev timer
unsigned long counterP = 0; // pump counter
uint8_t butt1;
uint8_t butt2;
uint8_t butt3;
uint8_t butt4;
void setup()
{
//Serial.begin(9600); //Comment out when NOT running DEBUG
//DMXSerial.init(DMXProbe); //Comment out for DEBUG
//DMXSerial.maxChannel(Dmxchannels); //Comment out for DEBUG
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
//Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial displays
display.display();
delay(1000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
display.drawBitmap(0,0,GSE_bmp,128,64,WHITE);
display.display();
delay(2000);
display.clearDisplay();
pinMode(RX_STATUS_PIN,OUTPUT);
pinMode (OUT1,OUTPUT);
pinMode (OUT2,OUTPUT);
pinMode (OUT3,OUTPUT);
pinMode (OUT4,OUTPUT);
pinMode (OUT5,OUTPUT);
pinMode (OUT6,OUTPUT);
pinMode (Vsens,OUTPUT);
pinMode (Menu_BTN,INPUT_PULLUP);
pinMode (Up_BTN,INPUT_PULLUP);
pinMode (Dwn_BTN,INPUT_PULLUP);
pinMode (Ent_BTN,INPUT_PULLUP);
pinMode (RTD1,INPUT);
pinMode (RTD2,INPUT);
digitalWrite(RX_STATUS_PIN,LOW);
digitalWrite(OUT1,LOW);
digitalWrite(OUT2,LOW);
digitalWrite(Vsens,HIGH);
ChSet=600; /// INITIALLY SET TO "600" TESTING need 0-699
debug("Switch Setting: ");
debugln(ChSet);
debugln(" ");
animateSF(SF_bmp, LOGO_WIDTH, LOGO_HEIGHT); // Run test animation
}
void loop()
{
butt1=(digitalRead(Menu_BTN));
butt2=(digitalRead(Up_BTN));
butt3=(digitalRead(Dwn_BTN));
butt4=(digitalRead(Ent_BTN));
if (ChSet>=1 && ChSet<=510){ //Machine is in DMX control mode
/*if (DMXSerial.receive()){
digitalWrite(RX_STATUS_PIN,HIGH);
int Count = Dmxchannels-1;
int Channel = 0;
for(int i=0;i<=Count;i++){
Channel = ChSet+i;
DMXvalue = DMXSerial.read(Channel); //Retrieve channel value
DMXreading[i]=DMXvalue;
}
CH1val=DMXreading[0];
CH2val=DMXreading[1];
if(CH1val <= 127){ //Fog Heater Activate above 50%
digitalWrite(OUT1,LOW);
digitalWrite(OUT2,LOW);
}
else{
Read();
Control();
}
if(T>=minT && CH2val >=51 && CH1val>127){
//Fog Pump Timer
currentMillisP=millis();
counterP = currentMillisP-prevMillisP;
if(counterP>=fogtime){ //Fog pump duty cycle timer initiate
prevMillisP=millis();
}
if(counterP<=fogstep1){
digitalWrite(OUT2,HIGH);
}
if(counterP>fogstep1 && counterP<=fogstep2){
if(CH2val <= 102){
digitalWrite(OUT2,LOW);
}
else{
digitalWrite(OUT2,HIGH);
}
}
if(counterP>fogstep2 && counterP<=fogstep3){
if(CH2val <= 153){
digitalWrite(OUT2,LOW);
}
else{
digitalWrite(OUT2,HIGH);
}
}
if(counterP>fogstep3){
if(CH2val <= 204){
digitalWrite(OUT2,LOW);
}
else{
digitalWrite(OUT2,HIGH);
}
}
}
else{digitalWrite(OUT2,LOW);
}
}*/
delay(100);
digitalWrite(RX_STATUS_PIN,LOW);
}
if (ChSet>=600 && ChSet<=699){ //Machine is in DEMO mode
DEMO(); // Run demo function
drawText(); //text
}
else{debugln("Machine is in Standby Mode");
debugln("");
delay(2000);
}
}
// START OF FUNCTIONS ############################################################
void animateSF(const uint8_t *bitmap, uint8_t w, uint8_t h) {
int8_t f, icons[NUMFLAKES][3];
// Initialize 'snowflake' positions
for(f=0; f< NUMFLAKES; f++) {
icons[f][XPOS] = random(1 - LOGO_WIDTH, display.width());
icons[f][YPOS] = -LOGO_HEIGHT;
icons[f][DELTAY] = random(1, 6);
}
for(int j=0;j<25;j++) { // Loop count..
display.clearDisplay(); // Clear the display buffer
// Draw each snowflake:
for(f=0; f< NUMFLAKES; f++) {
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, SSD1306_WHITE);
}
display.display(); // Show the display buffer on the screen
delay(150); // Pause second
// Then update coordinates of each flake...
for(f=0; f< NUMFLAKES; f++) {
icons[f][YPOS] += icons[f][DELTAY];
// If snowflake is off the bottom of the screen...
if (icons[f][YPOS] >= display.height()) {
// Reinitialize to a random position, just off the top
icons[f][XPOS] = random(1 - LOGO_WIDTH, display.width());
icons[f][YPOS] = -LOGO_HEIGHT;
icons[f][DELTAY] = random(1, 6);
}
}
}
}
void drawText(void) {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
display.setCursor(0,0);
display.println(F("Global "));
display.setTextSize(1); display.println(F("Special Effects "));
display.println();
display.setTextColor(SSD1306_WHITE);
display.print(F("TEMP: "));
if(T<=minT){display.setTextSize(1); display.println(F("Heating")); }
else{display.setTextSize(1); display.print(T);display.println(F(" C")); }
display.println();
if(butt1==LOW){display.print("Menu"); }
if(butt2==LOW){display.print("Up"); }
if(butt3==LOW){display.print("Down"); }
if(butt4==LOW){display.print("Enter"); }
display.display();
delay(250);
}
void Read(){ //measure running average and calculate temperature
runtotal = runtotal-samples[ReadIndex]; // Remove oldest entry
Vout = analogRead(RTD1); // Read next value
debug("Vout: ");
debugln(Vout);
samples[ReadIndex] = Vout; //Add newest reading to sample index
runtotal = runtotal + Vout; //Add newest reading to sum
ReadIndex =(ReadIndex+1) % NumS; // increment and rollover index
Vavg = runtotal / NumS;
debug ("Vavg: ");
debugln (Vavg);
R21 = (R1 / ((Vin / Vavg)- 1.0)); // calculate RTD resistance
debug ("RTD 1 Resistance = ");
debugln (R21);
// calculate T = -1*{[sqrt(-0.00232*R2 + 17.59246) - 3.908] / 0.00116}
T = -0.00232*R21+17.59246;
T = sqrt(T);
T = T-3.908;
T /= 0.00116;
T *= -1.0;
debug ("Current T: ");
debugln (T);
}
void Control(){ //Proportional control function every Tc interval
if (T>-20 && T<600){
currentMillis=millis();
if(currentMillis-prevMillis>=Tc){
prevMillis=millis();
}
else {counter = currentMillis-prevMillis;}
if (T <= setpoint){
error = setpoint - T;
if (error >= min_control){
duty_on = Tc;
}
if (error < min_control){
duty_on = Tc*(error/min_control);
}
if (duty_on>=counter){
digitalWrite(OUT1,HIGH);
}
else{digitalWrite (OUT1,LOW);}
debugln ("heating");
}
if (T > setpoint){
digitalWrite (OUT1,LOW);
debugln("Over Temp");
}
}
else{digitalWrite(OUT1,LOW);}
}
void DEMO()
{
debugln("Demo Mode");
Read();
Control();
if (T>=minT){
currentMillis=millis();
if(currentMillis-prevMillis>=DEMOtime){ //Fog pump duty cycle timer initiate
prevMillis=millis();
}
if(currentMillis-prevMillis<=DEMOstep){
digitalWrite(OUT2,HIGH);
}
else{
digitalWrite(OUT2,LOW);
}
}
//delay(250);//For Debugging only
}