Arduino UNO:
Động cơ RC Servo:
Code 1 RC Servo:
#include <Servo.h>Servo RCservo;void setup() {
RCservo.attach(9);
}void loop() {
RCservo.write(90);
delay(1000);
}
Code 1 RC Servo và 1 nút nhấn:
#include <Servo.h>Servo RCservo;int nutnhan = 2;void setup() {
RCservo.attach(9);pinMode(nutnhan, INPUT_PULLUP);
}void loop() {if (digitalRead(nutnhan) == 0) {RCservo.write(0);delay(100);}if (digitalRead(nutnhan) == 1) {RCservo.write(180);delay(100);}}
Code 2 RC Servo và 2 nút nhấn:
#include <Servo.h>Servo RCservo;Servo RCservo2;int nutnhan = 2;int nutnhan2 = 3;void setup() {
RCservo.attach(9);RCservo2.attach(10);pinMode(nutnhan, INPUT_PULLUP);pinMode(nutnhan2, INPUT_PULLUP);
}void loop() {if (digitalRead(nutnhan) == 0) {RCservo.write(0);delay(20);}if (digitalRead(nutnhan) == 1) {RCservo.write(90);delay(20);}}if (digitalRead(nutnhan2) == 0) {RCservo2.write(180);delay(20);}if (digitalRead(nutnhan2) == 1) {RCservo2.write(90);delay(20);}