NOTE: The code included AND mentioned in the comments will still work in 2021 - however not all parts are necessary. For example the very "weird" for
loop that seems to do nothing was fixing a bug back when this tutorial was first posted. Keep that in mind :)
One of things people want to do with Arduino is controlling things with serial monitor. Here are some command project uses:
myservo.write();
- Sends a position information to the servo
if(Serial.availiable())
- If serial monitor is available, then continues the loop between {
and }
intstate=Serial.parseInt();
- sets "state" to number, that has been sent to serial monitor
More about parseInt
- reads every number, sent to the serial monitor. It can read only numbers, not letters etc.
Important - Servo coding in this project is a bit different:
10 degrees = 0 degrees
90 degrees = 90 degrees
169 degrees = 180 degrees
You may be saying. "What? That doesn't make any sense" Well, yes and no at the same time. Some servos cannot read properly and will take 170 as 180°- depends on the speed and quality.
Comments