control servo by number







#include <Servo.h>
const int SERVO=7;  // servo on in 7
Servo myServo;
int val;
void setup()
{
 Serial.begin(9600);       //Serial Port at 9600 baud
 //Set pins as outputs
 myServo.attach(SERVO);
  Serial.print("angle degree =  ");       // input angle val
}
void loop()
{
 //Keep working as long as data is in the buffer
 while (Serial.available() > 0)
{
 val = Serial.parseInt();         // valid integer
 if (Serial.read() == '\n')         //Done transmitting
 Serial.print(val);   //print val
  Serial.println("  degree   ");       // print unit degree
    Serial.print("angle degree =  ");    // keep printing the next val
 {
 //set servo
 myServo.write(val); 
 }}}

Comments

Popular posts from this blog