I am working on an Arduino Nano project to control a equatorial telescope mount using two stepper motors and Bluetooth being generated from Keuwlsoft's Bluetooth controller. The Keuwlsoft program send 1-2 digit codes to the Nano via a Xbee Bluetooth interface.
Only the commands to move the stepper motors ("B" & "E") are being sent every 100ms...all other functions send the character once.
Everything works but the stepper motors move slowly even when given a fast setSpeed setting.
Please look over my code and suggest a way to modify it for better stepper operation...I have tried everything I can think of.
inside any IF statement. Just put it at the end of loop() so it gets called every time loop() repeats. And make sure that loop() can repeat much faster than the fastest step rate that you require.
The same for the other motor.
The way your program is written now runSpeed() will only be called once for every time that a 'B' is received.
That LCD code will also slow things down. The LCD does not need to be updated on every iteration of loop().
Is that a program you wrote yourself or one you found somewhere? Either way it is a bit of a dog's breakfast.
Serial.parseInt() is also slow. Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.
Separate the business of receiving data from the business of setting the AccelStepper parameters and that from the business of actually making the motors move.
If you want some action to happen while a button or key is pressed send a message when the key is pressed and send a separate message when it is released. For example send 'B' when it is pressed and 'b' when it is released.
Thanks for the information...I solved the problem!
I did what you suggested and moved the Motor_1.runSpeed() and Motor_2.runSpeed() to the end of the loop, changed the Motor Stop commands to "b" & "e" and added the following lines to the Motor Stop command...If (BluetoothData=='b') { Motor_1.setSpeed(0); Motor_1.stop() }.
Did this for both motors and now everything works as planned.