Hello
Have problem with code, getting error:
#define BLYNK_PRINT Serial
#include <SPI.h>
#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[] = "b0d68xxxxxxxxxxxxxxcx02a7185";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Prxxxxx";
char pass[] = "ghxxxxx0";
// 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") ;
terminal.flush();
}
void setup()
{
Serial.begin(9600);
delay(10);
EspSerial.begin(ESP8266_BAUD);
delay(10);
rightStepper.setSpeed(18);
leftStepper.setSpeed(18);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
delay(10);
terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
terminal.flush();
delay(10);
}
BLYNK_WRITE(V0) {
param.asInt() ? Control(1) : Control(5);
}
BLYNK_WRITE(V1) {
param.asInt() ? Control(2) : Control(5);
}
BLYNK_WRITE(V3) {
param.asInt() ? Control(3) : Control(5);
}
BLYNK_WRITE(V2) {
param.asInt() ? Control(4) : Control(5);
}
BLYNK_WRITE(V4) {
param.asInt() ? Control(5);
}
void Control(int state) {
switch(state){
case 1:
//move forward
rightStepper.step(1);
leftStepper.step(-1);
break;
case 2:
//move backward
rightStepper.step(-1);
leftStepper.step(1);
break;
case 3:
//move right
rightStepper.step(1);
leftStepper.step(1);
break;
case 4:
//move left
rightStepper.step(-1);
leftStepper.step(-1);
break;
case 5:
//stop
rightStepper.step(0);
leftStepper.step(0);
break;
}
}
void loop()
{
Blynk.run();
}
Error:
Arduino: 1.8.1 (Windows 7), Board: "Arduino/Genuino Uno"
C:\Users\xxxxxxxx\Documents\Arduino\robot1_esp_blynk\robot1_esp_blynk.ino: In function 'void BlynkWidgetWrite5(BlynkReq&, const BlynkParam&)':
robot1_esp_blynk:43: error: a function-definition is not allowed here before '{' token
{
^
robot1_esp_blynk:111: error: expected '}' at end of input
}
^
exit status 1
a function-definition is not allowed here before '{' token