Hi Railroader,
Please find the sketch in question
regards
type or paste code here
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled 2"
https://create.arduino.cc/cloud/things/b3585832-5a20-4891-b84e-7ee90d5cc477
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
int SO_pin;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "max6675.h"
LiquidCrystal_I2C lcd(0x27,16,2);
volatile unsigned int encoderPos = 60; // Inital value for set temp
static boolean MesLessThanSet;
static boolean rotating = false; // debounce management
// interrupt service routine vars
boolean A_set = false;
boolean B_set = false;
//TemSensor
int CLK = 13;
int CS = 10;
int SO = 12;
int relay = 7;
//Encoder
int dt_pin = 3;
int clk_pin = 2;
int clk_old = 0;
static int SetTemp;
int MesTemp;
MAX6675 temp_sensor(CLK, CS, SO);
struct debState
{
boolean InpOld;
int timer;
};
struct debCnt
{
int LtH;
int HtL;
};
debState St1 = {0};
debCnt Ct1 = {0};
//Definining Termometer Icon
byte tempchar1[8]={B00000, B00001, B00010, B00100, //Row 0, Col 2
B00100, B00100, B00100, B00111,};
byte tempchar2[8]={B00111, B00111, B00111, B01111, //Row 1, Col 2
B11111, B11111, B01111, B00011,};
byte tempchar3[8]={B00000, B10000, B01011, B00100, //ROW 0, Col 3
B00111, B00100, B00111, B11100,};
byte tempchar4[8]={B11111, B11100, B11100, B11110, //Row 1, Col 3
B11111, B11111, B11110, B11000,};
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
int State;
rotating = true; // reset the debouncer
lcd.setCursor(0,0);
lcd.print("Set_Temp:");
lcd.setCursor(9,0);
SetTemp = encoderPos;
lcd.print(SetTemp);
lcd.print(char(223));
lcd.print("C");
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Mes_Temp:");
lcd.setCursor(9,1);
MesTemp = temp_sensor.readCelsius();
delay(400);
lcd.print(MesTemp);
lcd.print(char(223));
lcd.print("C");
lcd.print(" ");
if(MesTemp <= SetTemp)
{
State = true;
}
else if(MesTemp > SetTemp)
{
State = false;
}
MesLessThanSet = debounce(State,&St1,&Ct1, 10);
// Serial.print(MesLessThanSet);
// Serial.print("\t ");
// Serial.println(St1.timer);
if(MesLessThanSet == true)
{
digitalWrite(relay,LOW);
printCustom(MesLessThanSet);
}
else if(MesLessThanSet == false)
{
digitalWrite(relay,HIGH);
printCustom(MesLessThanSet);
}
}
//Debounce
boolean debounce(boolean x, debState *st, debCnt *cn, int rtr)
{
if(x == st->InpOld)
{
st->timer = 0;
}
else
{
if(st->timer >= ((x!=false) ? cn->LtH : cn->HtL))
{
st->timer = 0;
st->InpOld = x;
}
else
{
st->timer += rtr;
}
}
return st->InpOld;
}
// Interrupt on A changing state
void doEncoderA() {
// debounce
if ( rotating ) delay (1); // wait a little until the bouncing is done
// Test transition, did things really change?
if ( digitalRead(2) != A_set ) { // debounce once more
A_set = !A_set;
// adjust counter + if A leads B
if ( A_set && !B_set )
encoderPos += 1;
rotating = false; // no more debouncing until loop() hits again
}
}
// Interrupt on B changing state, same as A above
void doEncoderB()
{
if ( rotating ) delay (1);
if ( digitalRead(3) != B_set ) {
B_set = !B_set;
// adjust counter - 1 if B leads A
if ( B_set && !A_set )
{
if(encoderPos > 0)
{
encoderPos -= 1;
}
}
rotating = false;
}
}
void printCustom(boolean x)
{
if(x == true)
{
lcd.createChar(1,tempchar1);
lcd.createChar(2,tempchar2);
lcd.createChar(3,tempchar3);
lcd.createChar(4,tempchar4);
lcd.setCursor(14,0);
lcd.write(1);
lcd.setCursor(14,1);
lcd.write(2);
lcd.setCursor(15,0);
lcd.write(3);
lcd.setCursor(15,1);
lcd.write(4);
}
else if(x == false)
{
lcd.setCursor(14,0);
lcd.print(" ");
lcd.setCursor(14,1);
lcd.print(" ");
lcd.setCursor(15,0);
lcd.print(" ");
lcd.setCursor(15,1);
lcd.print(" ");
}
}
/*
Since SetTemp is READ_WRITE variable, onSetTempChange() is
executed every time a new value is received from IoT Cloud.
*/
void onSetTempChange() {
// Add your code here to act upon SetTemp change
}
/*
Since Power is READ_WRITE variable, onPowerChange() is
executed every time a new value is received from IoT Cloud.
*/
void onPowerChange() {
// Add your code here to act upon Power change
}
/*
Since OvenChart is READ_WRITE variable, onOvenChartChange() is
executed every time a new value is received from IoT Cloud.
*/
void onOvenChartChange() {
// Add your code here to act upon OvenChart change
}
/*
Since MesTemp is READ_WRITE variable, onMesTempChange() is
executed every time a new value is received from IoT Cloud.
*/
void onMesTempChange() {
// Add your code here to act upon MesTemp change
}
/*
Since SO is READ_WRITE variable, onSOChange() is
executed every time a new value is received from IoT Cloud.
*/
void onSOChange() {
// Add your code here to act upon SO change
}
/*
Since SOPin is READ_WRITE variable, onSOPinChange() is
executed every time a new value is received from IoT Cloud.
*/
void onSOPinChange() {
// Add your code here to act upon SOPin change
}