bangnaga

Arduino Servo USB Port

Jan 17th, 2013
99
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Servo.h>
  2. #define PINSERVO 2 //Set Pin signal servo ke pin 2 port digital Arduino
  3. Servo servo1;
  4. void setup()
  5. {
  6.   pinMode(PINSERVO, OUTPUT);
  7.   servo1.attach(PINSERVO);
  8.   Serial.begin(115200);
  9.   Serial.println("Set Bitrate = 115200");
  10.   Serial.println("Masukkan nilai derajat diakhir karakter d untuk mengeksekusi.");
  11. }
  12.  
  13. void loop()
  14. {
  15.   static int val = 0;
  16.  
  17.   if (Serial.available())
  18.   {
  19.     char ch = Serial.read();
  20.  
  21.     switch(ch)
  22.     {
  23.       case '0'...'9':
  24.         val = val * 10 + ch - '0';
  25.         break;
  26.       case 'd':
  27.         servo1.write(val);
  28.         Serial.println(val, DEC);
  29.         val = 0;
  30.         break;
  31.     }
  32.   }
  33. }
RAW Paste Data