bangnaga icon

Arduino Multi Servo Serial

bangnaga | PRO | 06/23/25 06:35:17 AM UTC (Edited) | 0 ⭐ | 180 👁️ | Never ⏰ | []
C++ |

880 B

|

None

|

0 👍

/

0 👎

// 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);
}
 
  

Comments