Servo I/O HW (number 9)
#include <Servo.h>
Servo myservo;
int led = 10;
int servo = 9;
int input = 0;
int correct_input = 0;
int abc = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
myservo.attach(servo);
pinMode(led, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
input = Serial.parseInt(); // set the variable input equal to read value
if (input<180){ // if the input is valid set the servo to read value
myservo.write(input);
Serial.println(input);
digitalWrite(led, LOW);
}
else{ //if input is invalid set the servo to 0 and print error, also turn on led
myservo.write(0);
Serial.println("ERROR");
digitalWrite(led, HIGH);
delay(500);
}
}
Servo myservo;
int led = 10;
int servo = 9;
int input = 0;
int correct_input = 0;
int abc = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
myservo.attach(servo);
pinMode(led, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
input = Serial.parseInt(); // set the variable input equal to read value
if (input<180){ // if the input is valid set the servo to read value
myservo.write(input);
Serial.println(input);
digitalWrite(led, LOW);
}
else{ //if input is invalid set the servo to 0 and print error, also turn on led
myservo.write(0);
Serial.println("ERROR");
digitalWrite(led, HIGH);
delay(500);
}
}
Comments
Post a Comment