IgorFX
New member
Доброго дня. Не могу разобраться где ошибка. Двигатель делает только один шаг по запросу.
Код:
#include <ESP8266WiFi.h>
#include <CustomStepper.h>
// -- USER EDIT --
const char* ssid = "SweetHome"; // YOUR WIFI SSID
const char* password = "555555"; // YOUR WIFI PASSWORD
// change this to your motor if not NEMA-17 200 step
//#define STEPS 2048 // Max steps for one revolution
#define RPM 5 // Max RPM
#define DELAY 5 // Delay to allow Wifi to work
CustomStepper stepper(13, 12, 16, 14, (byte[]){8, B1000, B1100, B0100, B0110, B0010, B0011, B0001, B1001}, 4075.7728395, 12, CW);// -- END --
boolean uppoint = false;
boolean downpoint = false;
int STBY = 5; // GPIO 5 TB6612 Standby
int LED = 2; // GPIO 0 (built-in LED)
// GPIO Pins for Motor Driver board
//Stepper stepper(STEPS, 13, 12, 14, 16);
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
void setup()
{
stepper.setRPM(8);
stepper.setSPR(4075.7728395);
Serial.begin(115200);
delay(5);
// prepare onboard LED
pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH);
// prepare STBY GPIO and turn on Motors
//pinMode(STBY, OUTPUT);
//digitalWrite(STBY, HIGH);
// Set default speed to Max (doesn't move motor)
//stepper.setSpeed(RPM);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("STEPPER: Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
// Blink onboard LED to signify its connected
blink();
blink();
}
void loop()
{
// Check if a client has connected
WiFiClient client = server.available();
if (!client)
{
return;
}
String respMsg = ""; // HTTP Response Message
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){delay(1);}
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
//client.flush();
if (req.indexOf("/stepper/up") != -1)
{
if (stepper.isDone() && uppoint == false)
stepper.setDirection(CW);
stepper.rotate(2);
uppoint = true;
//digitalWrite(STBY, LOW);
blink();
respMsg = "OK: MOTOR Going Up";
}
if (req.indexOf("/stepper/down") != -1)
{
if (stepper.isDone() && downpoint == false)
stepper.setDirection(CCW);
stepper.rotate(2);
uppoint = false;
downpoint = true;
//digitalWrite(STBY, HIGH);
blink();
respMsg = "OK: MOTOR Going Down";
}
client.flush();
// Prepare the response
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n";
if (respMsg.length() > 0)
s += respMsg;
else
s += "OK";
s += "\n";
// Send the response to the client
client.print(s);
delay(1);
Serial.println("Client disconnected");
// The client will actually be disconnected
// when the function returns and 'client' object is detroyed
// Match the request
stepper.run();
}
void blink() {
digitalWrite(LED, LOW);
delay(500);
digitalWrite(LED, HIGH);
delay(500);
}