Hi everyone,
I have managed to make two Nema 17 accelerate, spin 5 times, and decelerate at the same time when I press a button once. Now I’m trying to do the same with a Blynk button, but I’m not sure how to incorporate my code with Blynk’s code and make it work.
I have managed to turn on and off an LED with Blynk with the setup bellow but nothing else. Online I haven’t found a clear example that shows me how to incorporate the functions I want to make within Blynks code.
Is there anyone that can help me with the matter? Thanks
Here is my setup:
- Nema 17 x2
- DRV8828 drivers x2
- Arduino Uno
- HM-10 Bluetooth board
- Push button x2
- IPhone 7
The code to run the stepper motors without Blynk is:
#include <Stepper.h>;
#include <AccelStepper.h>
const int buttonPin1 = 2;
const int REDledPin = 4;
const int buttonPin2 = 3; // the number of the pushbutton pin
const int GREENledPin = 5; // the number of the LED pin
int buttonState1 = 0;
int buttonState2 = 0;
AccelStepper stepper1(1, 9, 8); // pin 3 = step, pin 6 = direction
AccelStepper stepper2(1, 7, 6); // pin 4 = step, pin 7 = direction
void setup() {
pinMode(REDledPin, OUTPUT);
pinMode(GREENledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState1 == HIGH) {
//Trun LED on:
digitalWrite(REDledPin, HIGH);
} else {
//Tun Off LED
digitalWrite(REDledPin, LOW);
}
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState2 == HIGH) {
//Trun LED on:
digitalWrite(GREENledPin, HIGH);
} else {
//Tun Off LED
digitalWrite(GREENledPin, LOW);
}
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState1 == HIGH) {
stepper1.setMaxSpeed(2000.0);
stepper1.setAcceleration(500.0);
stepper1.moveTo(1000);
stepper2.setMaxSpeed(2000.0);
stepper2.setAcceleration(500.0);
stepper2.moveTo(1000);
} if (buttonState2 == HIGH) {
stepper1.setMaxSpeed(2000.0);
stepper1.setAcceleration(500.0);
stepper1.moveTo(-1000);
stepper2.setMaxSpeed(2000.0);
stepper2.setAcceleration(500.0);
stepper2.moveTo(-1000);
}
stepper1.run();
stepper2.run();
}