Advertisement
Guest User

Untitled

a guest
Jun 10th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <Servo.h> // servo library
  2. Servo myservo1, myservo2; // servo name
  3.  
  4.  
  5.  
  6.  
  7. void setup()
  8. {
  9. myservo1.attach(6); // attach servo signal wire to pin 9
  10. myservo2.attach(5);
  11. //Setup usb serial connection to computer
  12. Serial.begin(9600);
  13.  
  14.  
  15. }
  16.  
  17. void loop()
  18. {
  19. //Read from bluetooth and write to usb serial
  20. if(Serial.available()>=2 )
  21. {
  22. unsigned int servopos = Serial.read();
  23. unsigned int servopos1 = Serial.read();
  24. unsigned int realservo = (servopos1 *256) + servopos;
  25. Serial.println(realservo);
  26.  
  27. if (realservo >= 1000 && realservo <1180) {
  28. int servo1 = realservo;
  29. servo1 = map(servo1, 1000, 1180, 0, 180);
  30. myservo1.write(servo1);
  31. Serial.println("Servo 1 ON");
  32. delay(10);
  33. }
  34. if (realservo >= 2000 && realservo <2180) {
  35. int servo2 = realservo;
  36. servo2 = map(servo2, 2000, 2180, 0, 180);
  37. myservo2.write(servo2);
  38. Serial.println("Servo 2 ON");
  39. delay(10);
  40. }
  41.  
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement