0% found this document useful (0 votes)
35 views1 page

Bluetooth

Uploaded by

harts.toys
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views1 page

Bluetooth

Uploaded by

harts.toys
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#define EN 8

// Direction pin
#define X_DIR 5

// Step pin
#define X_STP 2

// A4988
int delayTime = 30;
int stps = 26400;

// Bluetooth Serial communication


char dataIn;

void step(boolean dir, byte dirPin, byte stepperPin, int steps)


{
digitalWrite(dirPin, dir);
delay(100);
for (int i = 0; i < steps; i++)
{
digitalWrite(stepperPin, HIGH);
delayMicroseconds(delayTime);
digitalWrite(stepperPin, LOW);
delayMicroseconds(delayTime);
}
}

void setup()
{
pinMode(X_DIR, OUTPUT);
pinMode(X_STP, OUTPUT);
pinMode(EN, OUTPUT);
digitalWrite(EN, LOW);

// Start Serial Communication at baud rate 9600


[Link](9600);
}

void loop()
{
// Check if data is available to read
if ([Link]() > 0)
{
dataIn = [Link](); // Read the incoming data

if (dataIn == 'F') // Move Forward


{
step(false, X_DIR, X_STP, stps);
}
else if (dataIn == 'B') // Move Backward
{
step(true, X_DIR, X_STP, stps);
}
}
}

You might also like