I want to make calculations in code, which in result will be used for defining position for stepper. But when I open serial monitor windows, there is always weird characters in first string. In second and further bottom strings numbers are correct (130.25).
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper1(AccelStepper::FULL4WIRE, A3,A1,A2,A0); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
AccelStepper stepper2(AccelStepper::FULL4WIRE, 0,2,1,3);
void setup()
{
// Change these to suit your stepper if you want
stepper1.setMaxSpeed(2000);
stepper2.setMaxSpeed(2000);
Serial.begin(9600);
}
void loop()
{
int a = 1000;
int b = 2;
float c = sqrt(a*a+b*b);
Serial.println(c);
delay(200);
stepper1.moveTo(c); // set target forward c steps
stepper2.moveTo(c); // set target forward c steps
while (stepper1.distanceToGo() != 0 || stepper2.distanceToGo() != 0)
{
stepper1.setSpeed(300);
stepper2.setSpeed(300);
stepper1.runSpeedToPosition();
stepper2.runSpeedToPosition();
}
}
then I got normal serial monitor data from beginning. How should code perform calculation to get the right value from beginning?