Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BLYNK_PRINT Serial
- #include <Stepper.h>
- #include <ESP8266_Lib.h>
- #include <BlynkSimpleShieldEsp8266.h>
- // You should get Auth Token in the Blynk App.
- // Go to the Project Settings (nut icon).
- char auth[] = "b0xxxxxxxxxxxxx2a7185";
- // Your WiFi credentials.
- // Set password to "" for open networks.
- char ssid[] = "Pxxxxxxca3";
- char pass[] = "gxxxxxxxx";
- // or Software Serial on Uno, Nano...
- #include <SoftwareSerial.h>
- SoftwareSerial EspSerial(2, 3); // RX, TX
- // Your ESP8266 baud rate:
- #define ESP8266_BAUD 9600
- ESP8266 wifi(&EspSerial);
- const int stepsPerRevolution = 2048;
- Stepper rightStepper(stepsPerRevolution, 8,10,9,11);
- Stepper leftStepper(stepsPerRevolution, 4,6,5,7);
- int state = 5;
- WidgetTerminal terminal(V5);
- BLYNK_WRITE(V5)
- {
- if (String("echo") == param.asStr()) {
- terminal.println("echo OK") ;
- } else {
- terminal.println("FAIL") ;}
- }
- void setup()
- {
- // Debug console
- Serial.begin(9600);
- delay(10);
- // Set ESP8266 baud rate
- EspSerial.begin(ESP8266_BAUD);
- delay(10);
- rightStepper.setSpeed(18);
- leftStepper.setSpeed(18);
- Blynk.begin(auth, wifi, ssid, pass);
- terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
- }
- BLYNK_WRITE(V0) {
- if (param.asInt() == 1) {
- state = 1; // forward
- } else {
- state = 5; // stop
- }
- Control();
- }
- BLYNK_WRITE(V1) {
- if (param.asInt() == 1) {
- state = 2; // backward
- } else {
- state = 5; // stop
- }
- Control();
- }
- BLYNK_WRITE(V3) {
- if (param.asInt() == 1) {
- state = 3; // right
- } else {
- state = 5; // stop
- }
- Control();
- }
- BLYNK_WRITE(V2) {
- if (param.asInt() == 1) {
- state = 4; // left
- } else {
- state = 5; // stop
- }
- Control();
- }
- void Control() {
- //move forward
- if (state == 1) {
- rightStepper.step(1);
- leftStepper.step(-1);
- }
- //move backward
- if (state == 2) {
- rightStepper.step(-1);
- leftStepper.step(1);
- }
- //move right
- if (state == 3) {
- rightStepper.step(-1);
- leftStepper.step(-1);
- }
- //move left
- if (state == 4) {
- rightStepper.step(1);
- leftStepper.step(1);
- }
- //do nothing
- if (state == 5) {
- rightStepper.step(0);
- leftStepper.step(0);
- }
- }
- void loop()
- {
- Blynk.run();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement