Added different speeds for up and down
This commit is contained in:
@@ -12,8 +12,11 @@
|
||||
*
|
||||
* 28BYJ-48 Default; stepperSpeed 1100.0
|
||||
* stepperAccel 175.0
|
||||
*
|
||||
* stepperSpeed[0] is upward speed
|
||||
* stepperSpeed[1] is downward speed
|
||||
*/
|
||||
float stepperSpeed = 1100.0; //Max Speed
|
||||
float stepperSpeed[2] = {1100.0,1100.0}; //Max Speed
|
||||
float stepperAccel = 175.0; //Acceleration Rate
|
||||
|
||||
/* Drive motor selection.
|
||||
|
||||
@@ -19,9 +19,11 @@ void configSave() {
|
||||
i+=sizeof(lastPosition);
|
||||
EEPROM.put(i,stepperAccel);
|
||||
i+=sizeof(stepperAccel);
|
||||
EEPROM.put(i,stepperSpeed);
|
||||
i+=sizeof(stepperSpeed);
|
||||
EEPROM.put(i,invertMotor);
|
||||
EEPROM.put(i,stepperSpeed[0]);
|
||||
i+=sizeof(stepperSpeed[0]);
|
||||
EEPROM.put(i,stepperSpeed[1]);
|
||||
i+=sizeof(stepperSpeed[1]);
|
||||
EEPROM.put(i,invertMotor[0]);
|
||||
i+=sizeof(invertMotor[0]);
|
||||
EEPROM.put(i,oldBrightness);
|
||||
i+=sizeof(oldBrightness);
|
||||
@@ -37,15 +39,17 @@ void configLoad() {
|
||||
i+=sizeof(lastPosition);
|
||||
EEPROM.get(i,stepperAccel);
|
||||
i+=sizeof(stepperAccel);
|
||||
EEPROM.get(i,stepperSpeed);
|
||||
i+=sizeof(stepperSpeed);
|
||||
EEPROM.get(i,stepperSpeed[0]);
|
||||
i+=sizeof(stepperSpeed[0]);
|
||||
EEPROM.get(i,stepperSpeed[1]);
|
||||
i+=sizeof(stepperSpeed[1]);
|
||||
EEPROM.get(i,invertMotor[0]);
|
||||
i+=sizeof(invertMotor);
|
||||
EEPROM.get(i,oldBrightness);
|
||||
i+=sizeof(oldBrightness);
|
||||
delay(20);
|
||||
Serial.print("Config Loaded | Version "); Serial.println(returnConfigVersion());
|
||||
Serial.print("Stepper: Speed|"); Serial.print(stepperSpeed); Serial.print(" Accel:"); Serial.println(stepperAccel);
|
||||
Serial.print("Stepper: Speed|"); Serial.print(stepperSpeed[2]); Serial.print(" Accel:"); Serial.println(stepperAccel);
|
||||
Serial.println("Current Position:" + savedPosition);
|
||||
}
|
||||
|
||||
@@ -130,7 +134,16 @@ void blynkRun() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
void speedCheck() { //Set speed based oin direction
|
||||
if (lastPosition < motorPos) {
|
||||
stepper.setMaxSpeed(stepperSpeed[1]); //Down Speed
|
||||
Serial.print("Speed set to "); Serial.println(stepperSpeed[1]);
|
||||
} else {
|
||||
stepper.setMaxSpeed(stepperSpeed[0]); //Up Speed
|
||||
Serial.print("Speed set to "); Serial.println(stepperSpeed[0]);
|
||||
}
|
||||
stepper.setAcceleration(stepperAccel); //Update acceleration
|
||||
}
|
||||
|
||||
|
||||
void motorControl() {
|
||||
@@ -150,11 +163,14 @@ void motorControl() {
|
||||
|
||||
//Blynk will set a vale to motorPos that is used to set where the motor should run to
|
||||
if (motorPos > 0) {
|
||||
speedCheck();
|
||||
|
||||
if (motorPos == 1) {stepper.moveTo(shade[0]);}
|
||||
if (motorPos == 2) {stepper.moveTo(shade[1]);}
|
||||
if (motorPos == 3) {stepper.moveTo(shade[2]);}
|
||||
if (motorPos == 4) {stepper.moveTo(shade[3]);}
|
||||
if (motorPos == 5) {stepper.moveTo(shade[4]);}
|
||||
|
||||
Serial.println(F("Blynk Move"));
|
||||
|
||||
lastPosition = motorPos; //Before reseting motorPos, save a copy to lastPosition
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
//version 2.5.0
|
||||
//Latest tested :
|
||||
const byte configVersion = 2; //This will prevent loading an old config from EEPROM
|
||||
const byte configVersion = 1; //This will prevent loading an old config from EEPROM
|
||||
|
||||
#include <AccelStepper.h>
|
||||
#include <EEPROM.h>
|
||||
@@ -215,7 +215,7 @@ void setup() {
|
||||
setSyncInterval(blynkRtcInterval);
|
||||
#endif
|
||||
|
||||
stepper.setMaxSpeed(stepperSpeed);
|
||||
stepper.setMaxSpeed(stepperSpeed[2]);
|
||||
stepper.setAcceleration(stepperAccel);
|
||||
|
||||
stepper.setCurrentPosition(savedPosition);
|
||||
|
||||
@@ -6,9 +6,10 @@ void sendBlynk() { //Blynk Feedback
|
||||
Blynk.virtualWrite(V11,shade[4]);
|
||||
Blynk.virtualWrite(V26,pulseMax);
|
||||
Blynk.virtualWrite(V27,pwmBrightness);
|
||||
Blynk.virtualWrite(V30,stepperSpeed);
|
||||
Blynk.virtualWrite(V30,stepperSpeed[0]);
|
||||
Blynk.virtualWrite(V31,stepperAccel);
|
||||
Blynk.virtualWrite(V32,invertMotor[1]);
|
||||
Blynk.virtualWrite(V34,stepperSpeed[1]);
|
||||
}
|
||||
|
||||
BLYNK_WRITE(V11) {
|
||||
@@ -66,7 +67,7 @@ BLYNK_WRITE(V28) {
|
||||
//------Configure device via Blynk
|
||||
|
||||
BLYNK_WRITE(V30) { //Speed
|
||||
stepperSpeed = param.asInt();
|
||||
stepperSpeed[0] = param.asInt();
|
||||
}
|
||||
|
||||
BLYNK_WRITE(V31) { //Acceleration
|
||||
@@ -79,4 +80,6 @@ BLYNK_WRITE(V32) { //Invert direction
|
||||
|
||||
BLYNK_WRITE(V33) { //Reset device for inverted setting
|
||||
resetFlag = param.asInt();
|
||||
BLYNK_WRITE(V34) {
|
||||
stepperSpeed[1] = param.asInt();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user