#include <AccelStepper.h>
#include <Servo.h>
#include <MultiStepper.h>
const int LED = 13;//bluetooh code
const int BTPWR = 12;//bluetooh code
char nombreBT[10] = "SkriPsipnJ";//bluetooh code
char velocidad ='4';//9600//bluetooh code
char pin [5]= "0000";//bluetooh code
int pinservo(9);
int state;
int flag=0;
int flag=2; // why tihis comment eror??
AccelStepper stepper1(1,7,6);// (Type:driver, STEP, DIR)
AccelStepper stepper2(1,5,4);
Servo Katrol ;
MultiStepper StepperControl;
void setup() {
// put your setup code here, to run once:
pinMode(LED, OUTPUT);//bluetooh code
pinMode(BTPWR, OUTPUT);//bluetooh code
digitalWrite(LED, LOW);//bluetooh code
digitalWrite(BTPWR, HIGH);//bluetooh code
Serial.begin(9600);//bluetooh code
Serial.print("AT");//bluetooh code
delay(1000);//bluetooh code
Serial.print("AT+NAME");//bluetooh code
Serial.print(nombreBT);//bluetooh code
delay(1000);//bluetooh code
Serial.print("AT+BAUD");//bluetooh code
Serial.print(velocidad);//bluetooh code
delay(1000);//bluetooh code
Serial.print("AT+PIN");//bluetooh code
Serial.print(pin);//bluetooh code
delay(1000);//bluetooh code
digitalWrite(LED, HIGH);//bluetooh code
stepper1.setMaxSpeed(300);
stepper2.setMaxSpeed(300);
StepperControl.addStepper(stepper1);
StepperControl.addStepper(stepper2);
Katrol.attach(pinservo);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available() > 0){
state = Serial.read();
flag=0;
if (state == 'F') {
stepper1.setCurrentPosition(0);
// Run the motor forward at 10 steps/second until the motor reaches 400 steps (2 revolutions):
while(stepper1.currentPosition() != 50)
{
stepper1.setSpeed(200);
stepper1.runSpeed();
}
if(flag == 0){
Serial.println("Go Forward!");
flag=1;
}
else if (flag == 2) {
Serial.println("Go Forward!");
flag=3;
}
}
if (state == 'B') {
stepper1.setCurrentPosition(0);
// Run the motor backward at 10 steps/second until the motor reaches 400 steps (2 revolutions):
while(stepper1.currentPosition() != -50)
{
stepper1.setSpeed(-200);
stepper1.runSpeed();
}
if(flag == 0){
Serial.println("Go Backward!");
flag=1;
}
}
if (state == 'R') {
stepper2.setCurrentPosition(0);
// Run the motor right at 50 steps/second until the motor reaches 400 steps (2 revolutions):
while(stepper2.currentPosition() != 50)
{
stepper2.setSpeed(200);
stepper2.runSpeed();
}
if(flag == 0){
Serial.println("Go Right!");
flag=1;
}
}
if (state == 'L') {
stepper2.setCurrentPosition(0);
// Run the motor left at 50 steps/second until the motor reaches 400 steps (2 revolutions):
while(stepper2.currentPosition() != -50)
{
stepper2.setSpeed(-200);
stepper2.runSpeed();
}
if(flag == 0){
Serial.println("Go Left!");
flag=1;
}
}
if (state == 'U') {
Katrol.write(90);
Serial.print("Servo : ");
Serial.println("UP");
}
if (state == 'D') {
Katrol.write(0);
Serial.print("Servo : ");
Serial.println("DOWN");
}
}
}