Once again i need assistance with my code. Trying to get control of my particle on IFTTT and thought that I could define BLYNK_WRITE as a function, i don’t think i’m going about it correctly though. Should i just wait for BLYNK IFTTT integration or should this work work with a little tweaking? Thanks for any help you can offer!
//#pragma SPARK_NO_PREPROCESSOR
#include "blynk/blynk.h"
#include "blynk/BlynkSimpleParticle.h"
#include "SparkCorePolledTimer/SparkCorePolledTimer.h"
#include "spark-dallas-temperature/spark-dallas-temperature.h"
#include "OneWire/OneWire.h"
#include "MCP23008-I2C/MCP23008-I2C.h" //I2C STUFF
#define ONE_WIRE_BUS D6 // Data wire is plugged into pin D5 on the particle
#define TEMPERATURE_PRECISION 12 // DS18B20 Thermometer Stuff
#define lock BLYNK_WRITE(7) // lock doors
#define unlock BLYNK_WRITE(6) // unlock doors
char auth[] = "token"; //BLYNK CE3
//char auth[] = "token"; //BLYNK CE2
OneWire oneWire(ONE_WIRE_BUS); // DS18B20 Thermometer Stuff
DallasTemperature sensors(&oneWire); // DS18B20 Thermometer Stuff
Adafruit_MCP23008 mcp; // I2C STUFF
SparkCorePolledTimer updateTimer(5000); //Create a timer object and set it's timeout in milliseconds
void OnTimer(void); //Prototype for timer callback method
float main, mainRaw, aux, auxRaw, acc, accRaw, light, lightRaw;
//defince temp address
DeviceAddress Thermometer1 = { 0x28, 0xFF, 0x44, 0x50, 0x16, 0x15, 0x3, 0xC };
DeviceAddress Thermometer2 = { 0x28, 0xFF, 0xD5, 0x4D, 0x16, 0x15, 0x3, 0xD3 };
DeviceAddress Thermometer3 = { 0x28, 0xFF, 0x2D, 0x37, 0x16, 0x15, 0x3, 0xF8 };
DeviceAddress Thermometer4 = { 0x28, 0xFF, 0x6A, 0x24, 0x16, 0x15, 0x3, 0xF0 };
//DeviceAddress Thermometer5 = { 0x28, 0xFF, 0xF5, 0x4F, 0x16, 0x15, 0x3, 0x2C };
// define temp bit resolution ie: int, float, double
double InTempC = -1;
double Temp1 = -1;
double Temp2 = -1;
double Temp3 = -1;
double Temp4 = -1;
//double Temp5 = -1;
void update18B20Temp(DeviceAddress deviceAddress, double &tempC);
//end temp stuff
//setupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetupsetup
void setup(){
Serial.begin(9600);
Blynk.begin(auth); // BLYNK initialization
updateTimer.SetCallback(OnTimer);
Particle.function("lock", lock);
Particle.function("unlock", unlock);
sensors.begin(); // DS18B20 initialization
sensors.setResolution(Thermometer1, TEMPERATURE_PRECISION);
sensors.setResolution(Thermometer2, TEMPERATURE_PRECISION);
sensors.setResolution(Thermometer3, TEMPERATURE_PRECISION);
sensors.setResolution(Thermometer4, TEMPERATURE_PRECISION);
// sensors.setResolution(Thermometer5, TEMPERATURE_PRECISION);
pinMode(A0, INPUT); //
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A5, INPUT);
// I2C STUFF
mcp.begin(); // use default address 0
mcp.pinMode(0, OUTPUT);
mcp.pinMode(1, OUTPUT);
mcp.pinMode(2, OUTPUT);
mcp.pinMode(3, OUTPUT);
mcp.pinMode(4, OUTPUT);
mcp.pinMode(5, OUTPUT);
mcp.pinMode(6, OUTPUT);
mcp.pinMode(7, OUTPUT);
// END I2C STUFF
}// END VOID SETUP BUT WHAT ABOUT I2C CODE BELOW BEFORE LOOP
// BLYNY WRITE NEEDS TO BE ABOVE LOOP BUT NOT IN SETUP LIKE THIS
// I2C STUFF
BLYNK_WRITE(0) {
if (param.asInt()) {
mcp.digitalWrite(0, HIGH);
delay(3000);
} else {
mcp.digitalWrite(0, LOW);}}
BLYNK_WRITE(1) {
if (param.asInt()) {
mcp.digitalWrite(1, HIGH);
} else {
mcp.digitalWrite(1, LOW);}}
BLYNK_WRITE(2) {
if (param.asInt()) {
mcp.digitalWrite(2, HIGH);
} else {
mcp.digitalWrite(2, LOW);}}
BLYNK_WRITE(3) {
if (param.asInt()) {
mcp.digitalWrite(3, HIGH);
} else {
mcp.digitalWrite(3, LOW);}}
BLYNK_WRITE(4) {
if (param.asInt()) {
mcp.digitalWrite(4, HIGH);
} else {
mcp.digitalWrite(4, LOW);}}
BLYNK_WRITE(5) {
if (param.asInt()) {
mcp.digitalWrite(5, HIGH);
} else {
mcp.digitalWrite(5, LOW);}}
BLYNK_WRITE(6) {
if (param.asInt()) {
mcp.digitalWrite(6, HIGH);
delay(500);
mcp.digitalWrite(6, LOW);
delay(500);
mcp.digitalWrite(6, HIGH);
delay(500);
} else {
mcp.digitalWrite(6, LOW);}}
BLYNK_WRITE(7) {
if (param.asInt()) {
mcp.digitalWrite(7, HIGH);
delay(500);
mcp.digitalWrite(7, LOW);
delay(500);
mcp.digitalWrite(7, HIGH);
delay(500);
} else {
mcp.digitalWrite(7, LOW);}}
//I2C STUFF
//looplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooplooploop//looplooplooplooplooplooploopl
void loop()
{
Blynk.run();
updateTimer.Update();
}
void OnTimer(void) { //Handler for the timer, will be called automatically
// DS18B20
sensors.requestTemperatures();
update18B20Temp(Thermometer1, InTempC);
Temp1 = (InTempC * 9)/5 + 32;
update18B20Temp(Thermometer2, InTempC);
Temp2 = (InTempC * 9)/5 + 31.33;
update18B20Temp(Thermometer3, InTempC);
Temp3 = (InTempC * 9)/5 + 31.67;
update18B20Temp(Thermometer4, InTempC);
Temp4 = (InTempC * 9)/5 + 32;
// update18B20Temp(Thermometer5, InTempC);
// Temp5 = (InTempC * 9)/5 + 32.12;
//delay(5000); // READ DELAY - TOOK THIS OUT AND IT GOT JUMPY WITH -127'S C AND 196'S F
updateTimer.Update(); // new stuff
}
void update18B20Temp(DeviceAddress deviceAddress, double &tempC)
{
tempC = sensors.getTempC(deviceAddress);
// read temperature and discard reading between 150 and -30
if ( Temp1 < 150 && Temp1 > -30) {
Blynk.virtualWrite(21, Temp1);
}
if ( Temp2 < 150 && Temp2 > -30) {
Blynk.virtualWrite(22, Temp2);
}
if ( Temp3 < 150 && Temp3 > -30) {
Blynk.virtualWrite(23, Temp3);
}
if ( Temp4 < 150 && Temp4 > -30) {
Blynk.virtualWrite(24, Temp4);
}
//if ( Temp5 < 150 && Temp5 > -30) {
// Blynk.virtualWrite(25, Temp5);
//}
// read analog ports
mainRaw = analogRead(A0);
auxRaw = analogRead(A1);
accRaw = analogRead(A2);
lightRaw = analogRead(A5);
// map analog input scale output
main = map(mainRaw, 0, 4096, 0, 1865);
aux = map(auxRaw, 0, 4096, 0, 1865);
acc = map(accRaw, 0, 4096, 0, 1865);
light = map(lightRaw, 0, 4050, 1100, 1500);
// correct display decimal place
main = (main / 100);
aux = (aux / 100);
acc = (acc / 100);
light = (light / 100);
Blynk.virtualWrite(10, main);
Blynk.virtualWrite(11, aux);
Blynk.virtualWrite(12, acc);
Blynk.virtualWrite(15, light);
}
error message
In file included from blynk/BlynkParticle.h:16:0,
from blynk/BlynkSimpleParticle.h:14,
from blynk/blynk.h:2,
from cruisecontrolce2.cpp:2:
blynk/BlynkApiParticle.h:78:6: warning: #warning "analogInputToDigitalPin not defined => Named analog pins will not work" [-Wcpp]
#warning "analogInputToDigitalPin not defined => Named analog pins will not work"
^
In file included from blynk/BlynkApi.h:17:0,
from blynk/BlynkApiParticle.h:15,
from blynk/BlynkParticle.h:16,
from blynk/BlynkSimpleParticle.h:14,
from blynk/blynk.h:2,
from cruisecontrolce2.cpp:2:
cruisecontrolce2.cpp: In function 'void setup()':
This looks like an error in blynk library. Would you like to create an issue on GitHub to let the author know?
CREATE ISSUE
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:54:5: error: expected primary-expression before 'void'
void BlynkWidgetWrite ## pin (BlynkReq& request, const BlynkParam& param)
^
blynk/BlynkHandlers.h:62:31: note: in expansion of macro 'BLYNK_WRITE_2'
#define BLYNK_WRITE(pin) BLYNK_WRITE_2(pin)
^
cruisecontrolce2.cpp:10:14: note: in expansion of macro 'BLYNK_WRITE'
#define lock BLYNK_WRITE(7) // lock doors
^
cruisecontrolce2.cpp:46:27: note: in expansion of macro 'lock'
Particle.function("lock", lock);
^
blynk/BlynkHandlers.h:54:5: error: expected primary-expression before 'void'
void BlynkWidgetWrite ## pin (BlynkReq& request, const BlynkParam& param)
^
blynk/BlynkHandlers.h:62:31: note: in expansion of macro 'BLYNK_WRITE_2'
#define BLYNK_WRITE(pin) BLYNK_WRITE_2(pin)
^
cruisecontrolce2.cpp:11:16: note: in expansion of macro 'BLYNK_WRITE'
#define unlock BLYNK_WRITE(6) // unlock doors
^
cruisecontrolce2.cpp:47:29: note: in expansion of macro 'unlock'
Particle.function("unlock", unlock);
^
make[1]: *** [../build/target/user/platform-6cruisecontrolce2.o] Error 1
make: *** [user] Error 2