# Running servo through serial monitor

I am totally new to this coding stuff, so i was hoping you guys would help me?
I want to change the angle of my servo through serial monitor, but no matter what i type it keeps resetting to 10 for some reason.

Wellâ€¦ this is how far i got:

#include <Servo.h>
Servo servoen;
int lol = 0;
void setup()
{
Serial.begin (9600);
servoen.attach(9);
}
void loop()
{
if (Serial.available() > 0)
{
}
servoen.write(lol);
{
Serial.println(lol);
delay(5);
}

}

10 is the ASCII code for new line.
Change the line ending control on the serial monitor to "none".
Better still, find out how to parse a multi digit number, so you don't have to translate positions to ASCII codes.

Please get into the habit of using code tags when posting code.

Thanx that fixed the "10" problem!

Do you have any examples on how to parse multi digit numbers into the thing? I have been looking into it, but didnt get very far

...aaaand i dont know what code tags is :S

Have a look at Serial Input Basics - simple reliable ways to receive data.

â€¦R

Damn. i wish i understood thisâ€¦ but i kind of dont. in the tutorial, i sort of understood that char converts ascii to normal numbers, but it only goes up to 137? is that right? cause i need 180 for this one. Is it array or string i need to look into?

I donâ€™t know where 137 comes from, but once youâ€™ve subtracted the ASCII value for the character â€˜0â€™ from each digit, the rest is simply decimal arithmetic.

137 == (1001) + (103) + (1*7)

oh my..... i shouldnt be doing this. I dont understand anything. thanx a lot for trying to help me, but i think im way too lost on this project

replace Serial.read() with Serial.parseInt() as the forum(And Robin2) suggested me.

What?? that did it! thank you so much! (and robin ofc :))

MalharD:
replace Serial.read() with Serial.parseInt() as the forum(And Robin2) suggested me.

Just to be perefctly clear I have NOT recommended the use of Serial.parseInt(). The whole point of the examples in Serial Input Basics is that they are non-blocking.

...R

lol. i dont even care xD it works now <3

lIlIl:
lol. i dont even care xD it works now <3

I think I have figured out lol

But what do xD and <3 mean.

And it does not seem to be a very kind response to my attempt at helping.

â€¦R