tripishadow

servo antonio

Dec 4th, 2021 (edited)
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. int HEADER_LEN = 2;
  4. const char seqHeader[] = {'~','!'};
  5.  
  6. Servo BOLA1; //Creación de servos
  7. Servo BOLA2;
  8. Servo BOLA3;
  9. Servo BOLA4;
  10.  
  11. int i = 0;
  12.  
  13. int incomingByte[8];
  14.  
  15. int val1;
  16. int val2;
  17. int val3;
  18. int val4;
  19.  
  20. void setup()
  21. {
  22. BOLA1.attach(9); // Asignación de pines
  23. BOLA2.attach(10);
  24. BOLA3.attach(11);
  25. BOLA4.attach(12);
  26. Serial.begin(115200);
  27. }
  28.  
  29. void loop()
  30. {
  31. if (Serial.available() >= 4) // Canales de Entrada al Arduino
  32.  
  33. {
  34.  
  35. for (int i=0; i<8; i++) { // Lectura del último byte en el buffer
  36.  
  37. incomingByte[i] = Serial.read();// Lectura de cada byte
  38. }
  39. //BOLA1
  40. val1 = incomingByte[0];
  41. val1 = map(val1, 0, 255, 0, 90 ); // Valor posición mínima y posición máxima del servo
  42. BOLA1.write(val1);
  43. delay(15);
  44. //BOLA2
  45. val2 = incomingByte[1];
  46. val2 = map(val2, 0, 255, 0, 90 );
  47. BOLA2.write(val2);
  48. delay(15);
  49. //BOLA3
  50. val3 = incomingByte[2];
  51. val3 = map(val3, 0, 255, 0, 90 );
  52. BOLA3.write(val3);
  53. delay(15);
  54. //BOLA4
  55. val4 = incomingByte[3];
  56. val4 = map(val4, 0, 255, 0, 90 );
  57. BOLA3.write(val4);
  58. delay(15);
  59.  
  60. }
  61. }
Add Comment
Please, Sign In to add comment