Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Arduino Kontrol 2 servo menggunakan serial terminal
- // Perintah 1 to 4
- // Power servo harus menggunakan power external jika menggunakan multi servo
- #include <Servo.h>
- Servo myservo;
- Servo myservo2;
- void setup()
- {
- Serial.begin(9600);
- myservo.attach(9);
- myservo2.attach(10);
- myservo.write(100);
- myservo2.write(100);
- delay(1000);
- }
- void loop() {
- if (Serial.available())
- {
- int state = Serial.parseInt();
- if (state == 1)
- {
- bukaservo1();
- }
- if (state == 2)
- {
- bukaservo2();
- }
- if (state == 3)
- {
- tutupservo1();
- }
- if (state == 4)
- {
- tutupservo2();
- }
- }
- }
- // Akhir Void Loop
- void bukaservo1(){
- myservo.write(100);
- }
- void bukaservo2(){
- myservo2.write(100);
- }
- void tutupservo1(){
- myservo.write(180);
- }
- void tutupservo2(){
- myservo2.write(180);
- }
Advertisement
Add Comment
Please, Sign In to add comment