i tried to organize things and to structure the code according to the order advised but i still have lots of errors and now my head hurts from trying to understand this new way ahah so far i have this…
// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_DHT/Adafruit_DHT.h"
/* MeLion GrowBox 0.1 */
#include "blynk/blynk.h"
// system defines
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
// Sensor Declaration
#define DHTPIN 4
#define DHTTYPE DHT11
#define ledRelay 1 // D1 pin output to Lighting LED's relay
#define fanRelay 2 // D2 pin output to Extraction Fan relay
#define heatRelay 3 // D3 pin output to Heating relay
#define dhtIn 4 // D4 pin input from DHT11
DHT dht(DHTPIN, DHTTYPE);
char auth[] = "";
// Garden setup
bool shutdownButton = 1;
// Moisture variables
int humid1;
int moistureBreakpoint = 60;
bool extractionInProgress = false;
int moistureValueVirtual;
bool extractionButton = 0;
// Temperature variables
int temp1;
int temperatureBreakpointLow = 20;
int temperatureBreakpointHigh = 23;
bool heatingInProgress = false;
bool heatingButton = 0;
// Lighting variables
bool lightingButton = 0;
// Timer variables
unsigned long Timer;
unsigned long milis;
// Outputs
pinMode(ledRelay, OUTPUT); //Output for LED Lighting relay
pinMode(fanRelay, OUTPUT); //Output for Extraction fan relay
pinMode(heatRelay, OUTPUT); //Output for Heater relay
pinMode(dhtIn, INPUT); //Input for the DHT pin
void setup()
{
Serial.begin(9600);
delay(1000);
Blynk.begin(auth);
dht.begin();
}
// Getting value of moistureBreakpoint
BLYNK_WRITE(V2)
{
int pinData = param.asInt();
moistureBreakpoint = pinData;
}
// Getting value of temperatureBreakpointLow
BLYNK_WRITE(V4)
{
int pinData = param.asInt();
temperatureBreakpointLow = pinData;
}
// Getting value of temperatureBreakpointHigh
BLYNK_WRITE(V5)
{
int pinData = param.asInt();
temperatureBreakpointHigh = pinData;
}
// Getting value of shutdownButton
BLYNK_WRITE(V6)
{
bool pinData = param.asInt();
shutdownButton = pinData;
}
// Getting value of extractionButton
BLYNK_WRITE(V6)
{
int pinData = param.asInt();
extractionButton = pinData;
}
// Getting value of LightingButton
BLYNK_WRITE(V7)
{
bool pinData = param.asInt();
lightingButton = pinData;
}
// Getting value of heatingbutton
BLYNK_WRITE(V8)
{
int pinData = param.asInt();
heatingButton = pinData;
}
void growBoxMaster()
{
milis = millis();
if(milis - Timer >= 1000UL)
{
Serial.println("********************* Timed pseudoloop execution *********************");
dhtReadings();
shutdownMaster();
moistureMaster();
heatingMaster();
lightingMaster();
Timer = millis();
}
}
// Get Readings
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a
// very slow sensor)
void dhtReadings();
{
float humid1 = dht.getHumidity();
// Read temperature as Celsius
float temp1 = dht.getTempCelcius();
// Read temperature as Farenheit
float f = dht.getTempFarenheit();
// Check if any reads failed and exit early (to try again).
if (isnan(humid1) || isnan(temp1) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index
// Must send in temp in Fahrenheit!
float hi = dht.getHeatIndex();
float dp = dht.getDewPoint();
float k = dht.getTempKelvin();
Serial.print("Humid: ");
Serial.print(humid1);
Serial.print("% - ");
Serial.print("Temp: ");
Serial.print(temp1);
Serial.print("*C ");
Serial.print(f);
Serial.print("*F ");
Serial.print(k);
Serial.print("*K - ");
Serial.print("DewP: ");
Serial.print(dp);
Serial.print("*C - ");
Serial.print("HeatI: ");
Serial.print(hi);
Serial.println("*C");
Serial.println(Time.timeStr());
Serial.println("done setup");
}
void shutdownMaster()
{
Serial.println("------- shutdownMaster started -------");
if(!shutdownButton)
{
startShutdown();
}
// Printing important values
Serial.print("shutdownButton - ");
Serial.println(shutdownButton);
}
void startShutdown()
{
digitalWrite(ledRelay, LOW);
digitalWrite(fanRelay, LOW);
digitalWrite(heatRelay, LOW);
Blynk.virtualWrite(28, 1023);
Serial.println("SHUTDOWN");
}
void moistureMaster()
{
Serial.println("------- moistureMaster started -------");
moistureVirtual()
if((humid1 > moistureBreakpoint) && (!extractionInProgress) && (extractionButton = HIGH))
{
extractionInProgress = true;
startExtraction();
}
if ((humid1 > moistureBreakpoint) && (!extractionInProgress) && (extractionButton = LOW))
{
extractionInProgress = true;
startExtraction();
}
if((humid1 < moistureBreakpoint) && (extractionInProgress) && (extractionButton = HIGH))
{
extractionInProgress = true;
startExtraction();
}
if ((humid1 < moistureBreakpoint) && (extractionInProgress) && (extractionButton = LOW))
{
extractionInProgress = false;
stopExtraction();
}
Serial.print("humid1 - ");
Serial.println(humid1);
Serial.print("extractionInProgress - ");
Serial.println(extractionInProgress);
Serial.print("moistureBreakpoint - ");
Serial.println(moistureBreakpoint);
}
void startExtraction()
{
digitalWrite(2, HIGH);
Blynk.virtualWrite(25, 1023);
Serial.println("Extraction - started");
}
void stopExtraction()
{
digitalWrite(2, LOW);
Blynk.virtualWrite(25, 0);
Serial.println("Extraction - stoped");
}
void moistureVirtual()
{
Blynk.virtualWrite(20, humid1);
}
void heatingMaster()
{
Serial.println("------- heatingMaster started -------");
temperatureVirtual();
if((temp1 < temperatureBreakpointLow) && (!heatingInProgress) && (!heatingButton))
{
heatingInProgress = true;
startHeating();
}
else if((temp1 < temperatureBreakpointLow) && (!heatingInProgress) && (heatingButton))
{
heatingInProgress = false;
stopHeating();
}
else if((temp1 >= temperatureBreakpointHigh) && (heatingInProgress) && (!heatingButton))
{
heatingInProgress = false;
stopHeating();
}
else if((temp1 >= temperatureBreakpointHigh) && (heatingInProgress) && (heatingButton))
{
heatingInProgress = true;
startHeating();
}
Serial.print("temp1 - ");
Serial.println(temp1);
Serial.print("heatingInProgress - ");
Serial.println(heatingInProgress);
Serial.print("temperatureBreakpointLow - ");
Serial.println(temperatureBreakpointLow);
Serial.print("temperatureBreakpointHigh - ");
Serial.println(temperatureBreakpointHigh);
Serial.print("heatingButton - ");
Serial.println(heatingButton);
}
void temperatureVirtual()
{
Blynk.virtualWrite(26, temp1);
}
void startHeating()
{
digitalWrite(3, HIGH);
Blynk.virtualWrite(24, 1023);
Blynk.virtualWrite(21, HIGH);
Serial.println("Heating - started");
}
void stopHeating()
{
digitalWrite(3, LOW);
Blynk.virtualWrite(24, 0);
Blynk.virtualWrite(21, LOW);
Serial.println("Heating - stoped");
}
void lightingMaster()
{
Serial.println("------- heatingMaster started -------");
if(!lightingButton)
{
startLighting();
}
else if (lightingButton)
{
stopLighting();
}
Serial.print("lightingButton - ");
Serial.println(lightingButton);
}
void startLighting()
{
digitalWrite(1, HIGH);
Blynk.virtualWrite(22, 1023);
Serial.println("Lighting - started");
}
void stopLighting();
{
digitalWrite(1, LOW);
Blynk.virtualWrite(22, 0);
Serial.println("Lighting - stopped");
}
void loop()
{
if (Blynk.connected()) Blynk.run();
// Initial timer setup
Timer = millis();
// Main function that times and calls all of the other subfunctions
growBoxMaster();
}
erros:
In file included from blynk/BlynkParticle.h:14:0,
from blynk/BlynkSimpleParticle.h:14,
from blynk/blynk.h:2,
from blynkt.cpp:6:
blynk/BlynkApiParticle.h:90:6: warning: #warning "analogInputToDigitalPin not defined => Named analog pins will not work" [-Wcpp]
#warning "analogInputToDigitalPin not defined => Named analog pins will not work"
^
blynkt.cpp:16:1: error: expected unqualified-id before 'else'
else if (lightingButton);
^
blynkt.cpp:42:10: error: expected constructor, destructor, or type conversion before '(' token
// Moisture variables
^
blynkt.cpp:43:10: error: expected constructor, destructor, or type conversion before '(' token
int humid1;
^
blynkt.cpp:44:10: error: expected constructor, destructor, or type conversion before '(' token
int moistureBreakpoint = 60;
^
blynkt.cpp:45:10: error: expected constructor, destructor, or type conversion before '(' token
bool extractionInProgress = false;
^
In file included from blynk/BlynkApi.h:17:0,
from blynk/BlynkApiParticle.h:14,
from blynk/BlynkParticle.h:14,
from blynk/BlynkSimpleParticle.h:14,
from blynk/blynk.h:2,
from blynkt.cpp:6:
blynkt.cpp: In function 'void BlynkWidgetWrite6(BlynkReq&, const BlynkParam&)':
This looks like an error in blynk library. Would you like to create an issue on GitHub to let the author know?
CREATE ISSUE
blynk/BlynkHandlers.h:155:10: error: redefinition of 'void BlynkWidgetWrite6(BlynkReq&, const BlynkParam&)'
void BlynkWidgetWrite ## pin (BlynkReq& request, const BlynkParam& param)
^
blynk/BlynkHandlers.h:163:31: note: in expansion of macro 'BLYNK_WRITE_2'
#define BLYNK_WRITE(pin) BLYNK_WRITE_2(pin)
^
blynkt.cpp:92:1: note: in expansion of macro 'BLYNK_WRITE'
^
This looks like an error in blynk library. Would you like to create an issue on GitHub to let the author know?
CREATE ISSUE
blynk/BlynkHandlers.h:155:10: error: 'void BlynkWidgetWrite6(BlynkReq&, const BlynkParam&)' previously defined here
void BlynkWidgetWrite ## pin (BlynkReq& request, const BlynkParam& param)
^
blynk/BlynkHandlers.h:163:31: note: in expansion of macro 'BLYNK_WRITE_2'
#define BLYNK_WRITE(pin) BLYNK_WRITE_2(pin)
^
blynkt.cpp:84:1: note: in expansion of macro 'BLYNK_WRITE'
^
blynkt.cpp: In function 'void growBoxMaster()':
blynkt.cpp:121:17: error: 'dhtReadings' was not declared in this scope
bool pinData = param.asInt();
^
blynkt.cpp: At global scope:
blynkt.cpp:135:1: error: expected unqualified-id before '{' token
milis = millis();
^
make[1]: *** [../build/target/user/platform-6blynkt.o] Error 1
make: *** [user] Error 2