I guess I missed something, I want to save a value set by BLYNK to the EEPROM. I got the save to work fine but it does not seem like I got the BLYNK part right, since a new value is not captured in the dimValue.
The simple target with the code is to save last value of a dimmer before turning of power and start with that value when power on.
(I also discovered that I must have the Blynk.begin(auth); after the Particle.variables in setup(); otherwise I wont get any readings in the console, is it suppose to be like that a bug or?)
#include <blynk.h>
int dimmerPin = A4; // PWM Dimmer 0-255
int dirPinA = A5; // Ain 1 sets dir.
int standbyPin = A7; // Standby, needs to be HIGH to activate motor controller
int dimValue; // light parameters
int last_dimValue; // light parameters
// uint32_t dimValue; // light parameters
// uint32_t last_dimValue; // light parameters
int addr = 10; // EEPROM set-up
char auth[]="4c80somethingelse9544e39de0c2d"; //BLYNK CODE
BLYNK_WRITE(V9)
{
analogWrite(dimValue, param.asInt());
analogWrite(dimmerPin, param.asInt());
}
void setup() {
// Blynk.begin(auth); //PROBLEM/BUG?: if I put Blynk.begin here Particle Variable wont "work"
Particle.variable("DimValue", dimValue); // For debugging
Particle.variable("lastDim", last_dimValue);
// Activate controller
pinMode(standbyPin, OUTPUT);
digitalWrite(standbyPin, HIGH);
// LED set-up
pinMode(dimmerPin, OUTPUT);
pinMode(dirPinA, OUTPUT);
digitalWrite(dirPinA, HIGH);
// Light goes to last state before power off when turned on again
EEPROM.put(addr, 30);
EEPROM.get(addr, dimValue);
analogWrite(dimmerPin, dimValue);
Blynk.begin(auth); //PROBLEM/BUG?: if I put Blynk.begin here Particle Variable "work" fine
}
void loop() {
if (dimValue != last_dimValue)
{
EEPROM.put(addr, dimValue);
last_dimValue=dimValue;
}
Blynk.run();
}