The code is very messy. The only difference between the code that you’ve provided is DS18B20_MAXRETRY = 4
and I used "Particle-OneWire.h"
insted of "OneWire/OneWire.h"
. I feel that the Photon is running very slow after the new programming, even to flash the new code it’s timing out, i reckon it’s stuck in the while loop.
Schematics from the DS18B20 is basically connected to A0 with 10k//10k pull-up resistor to 3.3V.
#include "Adafruit_GFX.h"
#include "Adafruit_SSD1306.h"
#include "blynk.h"
#include "pid.h"
#include "Particle-OneWire.h"
#include "DS18B20.h"
double Setpoint, Input, Output;
double aggKp=4, aggKi=0.2, aggKd=1;
double consKp=1, consKi=0.05, consKd=0.25;
//PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, PID::DIRECT);
//PID myPID(&Input, &Output, &Setpoint,2,5,1, PID::DIRECT);
PID myPID(&Input, &Output, &Setpoint,1,4,0.15, PID::DIRECT);
#define OLED_RESET D4
Adafruit_SSD1306 display(OLED_RESET);
DS18B20 ds18b20 = DS18B20(A0, true); // 1-wire signal on pin A0
int DS18B20nextSampleTime;
int DS18B20_SAMPLE_INTERVAL = 2000;
int DS18B20_MAXRETRY =4;
float tempHive;
int dsAttempts = 0;
int element = D3; //element PWM
int xaxis = A5; //X axis buttom
int yaxis = A4; //Y axis buttom
int swb = A3; //Press buttom
int pump = D5; //Pump
float celsius;
float oldcelsius;
float t1;
float t2;
float zeromillis=0; //zero millis for boil time calculate
int fermentationtime = 0; //fermentation notification;
unsigned long ti=0; //calculate seconds left
int h = 0; //calculate minutes left
int t = 0;
int notification = 0; //secure to notify just once
int Tmash = 66; //Mash cooking Temp
int end=0; //end of the menu
int X; //X axis
int Y; //Y axis
int SW; //Middle buttom pressed
int tree=0; //menu tree
int sparge=15; //sparge time
int timer = 61; //Mash time in minutes
int tboil = 10; //Boil timer
int boiltemp=101; //boil temperature
int hopadd=2; //Hop addition
int first=60;
int second=15; //Hop addition timer to the end in minutes
bool conf=false; //exit menu
int mashtime=1; //finish of mashtime
int boiltime=0; //finish of boil time
int aftertemp=0; //timer after temp reach desired level
int sliderV3=0;
char auth[] = "b4706060e3da4f918ebb75e3277ecb3c";
BLYNK_WRITE(V3)
{
sliderV3 = param.asInt(); // assigning incoming value from pin V1 to a variable
}
static const unsigned char beer[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x73, 0xfc, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x9c, 0x07, 0xf9, 0xf9, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf9, 0x00, 0x1e, 0xe7, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xf3, 0x0c, 0xc7, 0xcf, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xe2, 0x0c, 0xf3, 0xbf, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe6, 0x5e, 0x3f, 0xbf, 0xcf, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc6, 0x5f, 0xfb, 0xdc, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xc6, 0x01, 0xf0, 0x51, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0x83, 0x00, 0x1e, 0x7f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x97, 0xf0, 0x3e, 0x6f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0xe3, 0xff, 0xff, 0x97, 0xff, 0xff, 0xaf, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x99, 0xf8, 0x3f, 0xff, 0x83, 0xff, 0xff, 0x28, 0x3f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xf0, 0x7f, 0xff, 0x4f, 0xe3, 0x83, 0xff, 0xff, 0x2f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xcf, 0xff, 0xff, 0xf3, 0xff, 0x83, 0xff, 0xff, 0x9f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x9f, 0xff, 0xff, 0xf8, 0xff, 0x87, 0xff, 0xfe, 0x1c, 0x0f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xbf, 0xff, 0xff, 0xff, 0x7d, 0x97, 0xff, 0xfe, 0x10, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xe3, 0x87, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xe3, 0xbe, 0x44, 0x0f, 0xe3, 0x8f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xf9, 0xff, 0xff, 0xff, 0xc9, 0xbe, 0x47, 0x8f, 0x81, 0xb5, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfb, 0xff, 0xff, 0xfe, 0x11, 0xbe, 0x2f, 0x37, 0xdf, 0x54, 0x1f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfb, 0xff, 0x87, 0xd8, 0xf9, 0xbe, 0x58, 0x7a, 0xc3, 0xef, 0xef, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfb, 0xff, 0x0f, 0x86, 0xe0, 0x3e, 0x5f, 0xf3, 0xfe, 0xaf, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfb, 0xfe, 0x70, 0x26, 0x7b, 0x7e, 0x5f, 0x33, 0xcf, 0xed, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xf9, 0xfc, 0xf1, 0xf7, 0x78, 0x7f, 0x0f, 0xf3, 0xff, 0xae, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfd, 0xfd, 0xf7, 0xff, 0xcc, 0x7f, 0x27, 0xf3, 0xff, 0xaf, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xf8, 0xf0, 0x00, 0x0c, 0x0f, 0x27, 0xc3, 0xff, 0xef, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfd, 0xf8, 0xf0, 0x00, 0x0c, 0xf7, 0xaf, 0xa3, 0xdf, 0xd7, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfd, 0xf8, 0xf1, 0x80, 0x0c, 0xf8, 0xf7, 0x63, 0x6f, 0xb9, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfd, 0xf8, 0xf1, 0x80, 0x0c, 0xfd, 0xfb, 0x7f, 0xf7, 0x3c, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfe, 0xf2, 0xf1, 0x80, 0x00, 0xf5, 0x7e, 0xff, 0xff, 0x7f, 0x3f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfe, 0xf0, 0xe1, 0x80, 0x00, 0x74, 0xf3, 0x8f, 0x9f, 0x7f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfe, 0xf0, 0xe1, 0x80, 0x00, 0x7c, 0xf1, 0xc0, 0x9f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfe, 0xe0, 0xe1, 0x80, 0x00, 0x79, 0xf9, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfe, 0xe2, 0xe1, 0x80, 0x00, 0x11, 0xfe, 0xf3, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfe, 0xe2, 0xe1, 0x80, 0x00, 0x79, 0x9e, 0xf8, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x40, 0xe1, 0x80, 0x00, 0x7d, 0x6e, 0xff, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x62, 0xe1, 0x80, 0x00, 0x75, 0x67, 0x7f, 0xf3, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x00, 0xe1, 0x80, 0x00, 0x75, 0xb1, 0xbf, 0xf3, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x90, 0xe1, 0x80, 0x00, 0x7d, 0xd8, 0x9f, 0xf9, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x90, 0xe1, 0x80, 0x00, 0x7d, 0xe0, 0x6f, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x70, 0xe1, 0x80, 0x00, 0x72, 0xf0, 0x70, 0xcc, 0x1f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xb0, 0xe1, 0x80, 0x00, 0x04, 0x60, 0x3f, 0xc6, 0x03, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x30, 0xe1, 0x80, 0x00, 0x78, 0x80, 0x1f, 0xc2, 0x00, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x90, 0xe1, 0x80, 0x00, 0x7d, 0xc0, 0x0f, 0xe0, 0x00, 0x3f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xd1, 0xe1, 0x80, 0x00, 0x7c, 0xc0, 0x07, 0xf0, 0x00, 0x3f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xd1, 0xe1, 0x80, 0x00, 0x6c, 0x80, 0x03, 0xec, 0x00, 0x1f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xd0, 0xe1, 0x80, 0x00, 0x7c, 0x80, 0x01, 0xe3, 0x00, 0x1f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xd0, 0xe1, 0x80, 0x00, 0x7b, 0x00, 0x00, 0xe1, 0x00, 0x0f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xd0, 0xe1, 0x80, 0x00, 0x70, 0x00, 0x00, 0x6c, 0x00, 0x0f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xd1, 0xe1, 0x80, 0x00, 0x50, 0x00, 0x00, 0x23, 0x00, 0x0f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xd0, 0x80, 0x00, 0x04, 0x74, 0x00, 0x00, 0x01, 0x80, 0x0f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xd0, 0x00, 0x00, 0x0e, 0x74, 0x00, 0x00, 0x0c, 0x00, 0x1f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xd1, 0x20, 0x40, 0x60, 0x24, 0x00, 0x00, 0x07, 0x00, 0x3f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xd3, 0x04, 0x0c, 0x40, 0x68, 0x00, 0x00, 0x01, 0x80, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xd2, 0x0c, 0x18, 0x00, 0x48, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xd2, 0x08, 0x10, 0x00, 0x4f, 0xf8, 0x00, 0x03, 0x03, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xd2, 0x08, 0x10, 0x00, 0x7f, 0xff, 0xf0, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xd2, 0x08, 0x10, 0x40, 0x7f, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xd2, 0x08, 0x00, 0x40, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xd2, 0x00, 0x10, 0x41, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xcb, 0x07, 0x00, 0x01, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
};
static const unsigned char alarm[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfc, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf8, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xe0, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x80, 0x7b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x81, 0xe3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfe, 0x03, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfe, 0x07, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfc, 0x0e, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfc, 0x1e, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xf8, 0x38, 0x0f, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xf8, 0x38, 0x1e, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xf0, 0x70, 0x38, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xe0, 0xe0, 0x78, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xe0, 0xe0, 0xe0, 0x3f, 0x80, 0x3f, 0xff, 0xff, 0xc3, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xe0, 0xe1, 0xe0, 0x7f, 0x80, 0x1f, 0xff, 0xff, 0x83, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xc1, 0x81, 0xc0, 0xfe, 0x00, 0x07, 0xff, 0xf9, 0x81, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xc3, 0x83, 0x83, 0xfe, 0x00, 0x07, 0xff, 0xf1, 0xc1, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x83, 0x83, 0x83, 0xfc, 0x0f, 0x03, 0xff, 0xe0, 0xc1, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x83, 0x87, 0x07, 0xfc, 0x1f, 0x83, 0xfc, 0x70, 0xe1, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x83, 0x07, 0x07, 0xf8, 0x3f, 0xc1, 0xf0, 0x70, 0x60, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x87, 0x0e, 0x0f, 0xf8, 0x3f, 0xc1, 0xf0, 0x70, 0x70, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x87, 0x0e, 0x0f, 0xf0, 0x7f, 0xc1, 0xf8, 0x30, 0x70, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x87, 0x0e, 0x1f, 0xf0, 0xff, 0xc1, 0xfc, 0x38, 0x70, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x0e, 0x0e, 0x1f, 0xe0, 0xff, 0xc1, 0xfc, 0x18, 0x30, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x0e, 0x0e, 0x3f, 0xe0, 0xff, 0xc1, 0xfc, 0x1c, 0x30, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x0e, 0x1c, 0x3f, 0xe0, 0xff, 0xc1, 0xfc, 0x1c, 0x30, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x0e, 0x1c, 0x3f, 0xe1, 0xff, 0xc1, 0xfc, 0x1c, 0x38, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x0e, 0x1c, 0x3f, 0xc1, 0xff, 0xc1, 0xfe, 0x1c, 0x38, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x0e, 0x1c, 0x3f, 0x83, 0xff, 0xc3, 0xfe, 0x1c, 0x38, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x0e, 0x1c, 0x3f, 0x03, 0xff, 0xc3, 0xfe, 0x1c, 0x38, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x0e, 0x0c, 0x3e, 0x03, 0xff, 0x83, 0xfc, 0x1c, 0x38, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x0e, 0x0e, 0x3e, 0x0f, 0xff, 0x87, 0xfc, 0x1c, 0x38, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x8e, 0x0e, 0x1c, 0x1f, 0xff, 0x87, 0xfc, 0x1c, 0x30, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x86, 0x0e, 0x18, 0x03, 0xff, 0x87, 0xfc, 0x1c, 0x30, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x86, 0x0e, 0x08, 0x00, 0xff, 0x87, 0xfc, 0x38, 0x70, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x83, 0x0e, 0x0c, 0x00, 0x07, 0x83, 0xf8, 0x38, 0x70, 0x7f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x83, 0x07, 0x0f, 0x80, 0x00, 0xc1, 0xf8, 0x70, 0x70, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x83, 0x83, 0x0f, 0xe0, 0x00, 0x01, 0xf0, 0x70, 0x70, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xc3, 0x83, 0xff, 0xff, 0x00, 0x01, 0xf0, 0x70, 0xe0, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xc1, 0x83, 0xff, 0xf8, 0x00, 0x01, 0xc0, 0xe0, 0xc1, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xe1, 0xcf, 0xff, 0xf8, 0x0c, 0x03, 0xc1, 0xc1, 0xc1, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xf8, 0x0f, 0xc3, 0x01, 0xc1, 0xc1, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xfe, 0x0f, 0xff, 0x03, 0xc3, 0xc3, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xe3, 0xff, 0xff, 0xfe, 0x1f, 0xfc, 0x07, 0x03, 0x83, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x0f, 0x07, 0x07, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x1c, 0x07, 0x07, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7c, 0x0e, 0x0f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x70, 0x1c, 0x0f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x3c, 0x1f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x70, 0x1f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xf0, 0x7f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc1, 0xc0, 0x7f, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
};
static const unsigned char heart[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x00, 0x00, 0x03, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xf0, 0x00, 0x7f, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x78, 0x00, 0xf0, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x3c, 0x01, 0xc0, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x0e, 0x07, 0xc0, 0x00, 0x0f, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x03, 0x07, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x03, 0x8e, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x03, 0xdc, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xce, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
/*static const unsigned char LOGO16_GLCD_BMP[] =
{ 0B11111111, 1111111111,
0B11111111, 0B11000000,
0B11111111, 0B11000000,
0B00000011, 0B11100000,
0B11110011, 1111111111111,
0B11111110, 1111111110,
0B01111110, 0B11111111,
0B00110011, 0B10011111,
0B00011111, 0B11111100,
0B00001101, 0B01110000,
0B00011011, 0B10100000,
0B00111111, 0B11100000,
0B00111111, 0B11110000,
0B01111100, 0B11110000,
0B01110000, 0B01110000,
0B00000000, 0B00110000 };*/
void setup() {
Serial.begin(9600);
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
myPID.SetMode(PID::AUTOMATIC);
// init done
Blynk.begin(auth);
//display.display(); // show splashscreen
display.clearDisplay(); // clears the screen and buffer
pinMode(xaxis, INPUT); //X axis buttom
pinMode(yaxis, INPUT); //Y axis buttom
pinMode(swb, INPUT); //Press buttom
pinMode(element, OUTPUT); //Element PWM
pinMode(pump, OUTPUT); //Pump
digitalWrite(pump, HIGH);
}
void loop() {
Blynk.run();
//while (end<1){
//startmenu(); }
if (millis() > DS18B20nextSampleTime) {
GetTemp();
Blynk.virtualWrite(V1,celsius);
}
if (mashtime==1){
Setpoint=Tmash-3;
PIDcontrol();
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print("Mash "); display.print(h); display.print(":"); display.print(ti);
display.setCursor(0,16);
display.print("Target "); display.print(Tmash); display.print("C");
display.setCursor(00,34);
display.setTextSize(3);
display.print("T="); display.print(celsius,1); display.print("C");
display.display();
if(celsius>=Tmash) {
aftertemp++;
if (aftertemp<=1){
zeromillis = millis(); } }
if (aftertemp>=1){
//ALARM DISPLAY AND NOTIFICATION SETTINGS
if (celsius < (Tmash-5) || celsius > (Tmash+5)){
t1 = (millis()-t1)/1000;
t2 = t2+t1;
if (notification<1 && t2>20){ //NOTIFY ONCE AFTER 20SEC
Blynk.notify("We have a problem");
notification++;
t2=0;
}
if (t2>20){ //SCREEN ALARM EVERY 20SEC
display.clearDisplay();
display.drawBitmap(0, 0, alarm, 128, 64, 1);
display.display();
delay (1000);
t2=0;
}
}
else{
t1=0;
t2=0;
notification = 0;
}
// splash screen beer/heart
if (t==8){
display.clearDisplay();
display.drawBitmap(0, 0, heart, 128, 64, 1);
display.display();
delay(1000);
display.clearDisplay();
display.drawBitmap(0, 0, beer, 128, 64, 1);
display.display();
delay(1000);
t=0;
}
t++;
t1 = millis();
h=(timer*60*1000-(millis()-zeromillis))/60000; //calculate minutes left
ti=(timer*60*1000-(millis()-zeromillis)-h*60000)/1000; //calculate seconds left
Blynk.virtualWrite(V0,h);
digitalWrite(pump, LOW); //turn pump On
}
else h=timer;
if (h==0 && ti==0) {
boiltime++;
mashtime--;
aftertemp=0;
h=tboil;
digitalWrite(pump, HIGH); //turn pump Off
Blynk.notify("SPARGE TIME");
tree=0;
}
}
if (boiltime==1){
SW = digitalRead(swb);
if (SW==LOW) tree++;
if (tree==0){
analogWrite(element,0,50);
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0,0);
display.print("Is sparge over?");
display.setCursor(36,36);
display.setTextColor(BLACK, WHITE); display.print("YES");
display.display();
}
if (tree>=1){
Setpoint=boiltemp;
PIDcontrol();
display.clearDisplay();
display.setCursor(0,0);
display.setTextColor(WHITE);
display.setTextSize(2);
display.print("BOIL "); display.print(h); display.print(":"); display.print(ti);
display.setCursor(0,16);
display.print("Target "); display.print(boiltemp); display.print("C");
display.setCursor(00,34);
display.setTextSize(3);
display.print("T="); display.print(celsius,1); display.print("C");
display.display();
if(celsius>=boiltemp) {
aftertemp++;
if (aftertemp<=1){
zeromillis = millis(); }
}
if (aftertemp>=1){
//ALARM DISPLAY AND NOTIFICATION SEETINGS
if (celsius < (boiltemp-5) || celsius > (boiltemp+5)){
t1 = (millis()-t1)/1000;
t2 = t2+t1;
if (notification<1 && t2>20){ //NOTIFY ONCE AFTER 20SEC
Blynk.notify("AZEDOU");
notification++;
t2=0;
}
if (t2>20){ //SCREEN ALARM EVERY 20SEC
display.clearDisplay();
display.drawBitmap(0, 0, alarm, 128, 64, 1);
display.display();
delay (1000);
t2=0;
}
}
else{
t1=0;
t2=0;
notification = 0;
}
// splash screen beer/heart
if (t==8){
display.clearDisplay();
display.drawBitmap(0, 0, heart, 128, 64, 1);
display.display();
delay(1000);
display.clearDisplay();
display.drawBitmap(0, 0, beer, 128, 64, 1);
display.display();
delay(1000);
t=0;
}
t++;
t1 = millis();
h=(tboil*60*1000-(millis()-zeromillis))/60000; //calculate minutes left
ti=(tboil*60*1000-(millis()-zeromillis)-h*60000)/1000; //calculate seconds left
Blynk.virtualWrite(V0,h);
if (h==second && ti==0) Blynk.notify("ADD HOP");
}
if (h==0 && ti==0) {
boiltime++;
mashtime--;
}
// splash screen beer/heart
if (t==8){
display.clearDisplay();
display.drawBitmap(0, 0, heart, 128, 64, 1);
display.display();
delay(1000);
display.clearDisplay();
display.drawBitmap(0, 0, beer, 128, 64, 1);
display.display();
delay(1000);
t=0;
}
}
}
if (boiltime==2 && mashtime==-1) {
analogWrite(element,0,50);
if (fermentationtime<1){
Blynk.notify("FERMENTATION TIME");
fermentationtime++; }
display.clearDisplay();
display.setCursor(00,10);
display.setTextSize(3);
display.println("TO THE");display.println("Fermenter");
display.display();
}
}
void GetTemp(){
/*if(!ds18b20.search()){
ds18b20.resetsearch();
celsius = ds18b20.getTemperature();
Serial.println(celsius);
while (!ds18b20.crcCheck() && dsAttempts < 4){
dsAttempts++;
if (dsAttempts == 3){
delay(1000);
}
ds18b20.resetsearch();
celsius = ds18b20.getTemperature();
continue;
}
dsAttempts = 0;
DS18B20nextSampleTime = millis() + DS18B20_SAMPLE_INTERVAL;
}
if(abs(oldcelsius-celsius>20)) return;
oldcelsius=celsius;*/
int i = 0;
do {
celsius = ds18b20.getTemperature();
} while (!ds18b20.crcCheck() && DS18B20_MAXRETRY > i++);
tempHive = (i < DS18B20_MAXRETRY) ? celsius : 99.9;
}
void PIDcontrol(){
Input = celsius;
myPID.Compute();
if (sliderV3!=0) Output=sliderV3;
Blynk.virtualWrite(V2, map(Output,0,255,0,100));
Output=Output*0.53; //Limit Element to 10A = 2400Watts
analogWrite(element,Output,50); //Output PIN to be set up
}