Hello,
I am trying to use serial input to control a esc for my brushless motor. I used some example code to read the user input data into the serial. When I read this data back though, it keeps reporting 49-58 for all my given inputs of 1-9... any ideas?
Here is a screen shot of what It returns when I input 1, 2, 3, 4, 5 respectively.
#include <Servo.h>
Servo esc; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 10; // variable to store the servo position
int serialdata=0;
void setup()
{
Serial.begin(9600);
esc.attach(8); // attaches the servo on pin 9 to the servo object
esc.write(180);
delay(50);
esc.write(0);
delay(50);
}
void loop()
// send data only when you receive data:
{
int incomingByte=0;
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
int speed_max=serialdata;
esc.write(speed_max);
delay(15);
/* for (pos = 0; pos < speed_max; pos ++) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
esc.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos =speed_max; pos>=1; pos--) // goes from 180 degrees to 0 degrees
{
esc.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
*/
}