Stuff
This commit is contained in:
@@ -46,6 +46,9 @@ bool invertMotor[2] = {false};
|
||||
int connectTimeout = 100; // How many attempts can we make before giving up on Blynk
|
||||
#define blynkRtcInterval = 30; // How often to sync the time. (Would be used for timers)
|
||||
|
||||
//Future option to use sketch without Blynk
|
||||
#define useBlynk
|
||||
|
||||
#include "blynk.h" //Contains Blynk login
|
||||
|
||||
//Comment the below line to disable Blynk Serail feedback
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
#define eepromStart 10
|
||||
|
||||
|
||||
byte returnConfigVersion() {
|
||||
byte grabbedVersion;
|
||||
EEPROM.get(2,grabbedVersion);
|
||||
EEPROM.get(eepromStart,grabbedVersion);
|
||||
return grabbedVersion;
|
||||
}
|
||||
|
||||
@@ -11,8 +11,9 @@ byte returnConfigVersion() {
|
||||
void configSave() {
|
||||
//Position 400 is reserved for the blynk token
|
||||
EEPROM.write(0,1); //Flag for autoload
|
||||
EEPROM.put(2,configVersion);
|
||||
int i=10;
|
||||
int i=eepromStart;
|
||||
EEPROM.put(i,configVersion);
|
||||
i+=sizeof(configVersion);
|
||||
EEPROM.put(i,savedPosition);
|
||||
i+=sizeof(savedPosition);
|
||||
EEPROM.put(i,lastPosition);
|
||||
@@ -34,8 +35,10 @@ void configSave() {
|
||||
}
|
||||
|
||||
void configLoad() {
|
||||
int i=10;
|
||||
EEPROM.get(5,savedPosition);
|
||||
int i=eepromStart;
|
||||
EEPROM.get(i,configVersion);
|
||||
i+=sizeof(configVersion);
|
||||
EEPROM.get(i,savedPosition);
|
||||
i+=sizeof(savedPosition);
|
||||
EEPROM.get(i,lastPosition);
|
||||
i+=sizeof(lastPosition);
|
||||
@@ -215,6 +218,9 @@ void checkInvert() {
|
||||
shade[i] = shade[i]*-1;
|
||||
}
|
||||
invertMotor[1] = invertMotor[0]; //Set change flag
|
||||
int _tempHold = stepperSpeed[0];
|
||||
stepperSpeed[0] = stepperSpeed[1];
|
||||
stepperSpeed[1] = _tempHold;
|
||||
configSave();
|
||||
Serial.print("Direction ");
|
||||
if (invertMotor[1] == true) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
//Latest tested :
|
||||
const byte configVersion = 1; //This will prevent loading an old config from EEPROM
|
||||
|
||||
|
||||
#include <AccelStepper.h>
|
||||
#include <EEPROM.h>
|
||||
|
||||
@@ -91,9 +92,6 @@ int pwmBrightness = 0;
|
||||
int pwmBrightnessOut = 0;
|
||||
int oldPWMBrightness = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
#include "wifi.h"
|
||||
#include "functions.h"
|
||||
#include "lightcontrol.h"
|
||||
@@ -217,8 +215,11 @@ void setup() {
|
||||
|
||||
EEPROM.begin(eepromSize); //Initialize the EEPROM with our selected size
|
||||
|
||||
if (EEPROM.read(0) == 1 && configMatch()) { //If flagged in EEPROM; we load our current position
|
||||
if (returnConfigVersion() == configVersion) { //If flagged in EEPROM; we load our current position
|
||||
configLoad();
|
||||
} else {
|
||||
configSave(); //Save default values to EEPROM if versions do not match
|
||||
Serial.println("Default Config Saved");
|
||||
}
|
||||
|
||||
|
||||
@@ -246,9 +247,9 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
|
||||
|
||||
oldBrightness = ledBrightness;
|
||||
oldPWMBrightness = pwmBrightness;
|
||||
pwmOld = pwmOn;
|
||||
currentDistance = stepper.distanceToGo();
|
||||
checkInvert();
|
||||
ArduinoOTA.handle();
|
||||
@@ -271,6 +272,8 @@ void loop() {
|
||||
if (timer(0,blynkRefresh)) { //Run blyk every other cycle
|
||||
blynkRun(); //Only run blynk when the stepper is not active
|
||||
}
|
||||
|
||||
Blynk.virtualWrite(V5,returnConfigVersion());
|
||||
|
||||
|
||||
if (setHome == true) {
|
||||
|
||||
@@ -7,20 +7,22 @@ void sendBlynk() { //Blynk Feedback
|
||||
if (oldPWMBrightness != pwmBrightness) {
|
||||
Blynk.virtualWrite(V27,pwmBrightness);
|
||||
}
|
||||
if ( pwmOld != pwmOn) {
|
||||
Blynk.virtualWrite(V28,pwmOn);
|
||||
}
|
||||
|
||||
Blynk.virtualWrite(V28,pwmOn);
|
||||
|
||||
|
||||
|
||||
if (firstRun == true) {
|
||||
Blynk.virtualWrite(V11,shade[4]);
|
||||
Blynk.virtualWrite(V26,pulseMax);
|
||||
Blynk.virtualWrite(V27,pwmBrightness);
|
||||
Blynk.virtualWrite(V30,stepperSpeed[0]);
|
||||
Blynk.virtualWrite(V34,stepperSpeed[1]);
|
||||
Blynk.virtualWrite(V31,stepperAccel);
|
||||
Blynk.virtualWrite(V32,invertMotor[1]);
|
||||
Blynk.virtualWrite(V34,stepperSpeed[1]);
|
||||
firstRun = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user