Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. static const int servo1pin = D3; // = 0, "D8" - close arm segment
  4. static const int servo2pin = D5; // = 14, "D14/SDA/D4" - far arm segment
  5. static const int servo3pin = D2; // = 4, "D13/SCK/D5" - rotation
  6. static const int delayMs = 2500;
  7.  
  8. String inputValue;
  9. int intValue = 1500;
  10. int target = 0;
  11.  
  12. Servo servo1;
  13. Servo servo2;
  14. Servo servo3;
  15.  
  16. void setup() {
  17. Serial.begin(115200);
  18. pinMode(servo1pin,OUTPUT);
  19. pinMode(servo2pin,OUTPUT);
  20. pinMode(servo3pin,OUTPUT);
  21. servo1.attach(servo1pin);
  22. servo2.attach(servo2pin);
  23. servo3.attach(servo3pin);
  24. servo1.writeMicroseconds(1500);
  25. servo2.writeMicroseconds(1500);
  26. servo3.writeMicroseconds(1500);
  27. }
  28.  
  29. void setPosition(unsigned int servo, unsigned int value) {
  30.  
  31. }
  32.  
  33. void loop() {
  34. if(Serial.available()){
  35. inputValue = Serial.readStringUntil(' ');
  36. target = inputValue.toInt();
  37.  
  38. inputValue = Serial.readStringUntil('\n');
  39. intValue = inputValue.toInt();
  40.  
  41. if (target == 1) {
  42. servo1.writeMicroseconds(intValue);
  43. }
  44. if (target == 2) {
  45. servo2.writeMicroseconds(intValue);
  46. }
  47. if (target == 3) {
  48. servo3.writeMicroseconds(intValue);
  49. }
  50. }
  51.  
  52. // servo1.writeMicroseconds(integerValue);
  53. // servo2.writeMicroseconds(integerValue);
  54. // servo3.writeMicroseconds(integerValue);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement