Advertisement
NaroxEG

INO - Arm Robot

Jul 6th, 2024
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2. #include <Servo.h>
  3.  
  4. Servo thumb;
  5. Servo index;
  6. Servo middle;
  7. Servo ring;
  8. Servo pinky;
  9.  
  10. SoftwareSerial bluetooth(3, 2); // RX, TX
  11.  
  12. void setup() {
  13.   Serial.begin(9600);
  14.   bluetooth.begin(9600);
  15.   thumb.attach(4);
  16.   index.attach(5);
  17.   middle.attach(6);
  18.   ring.attach(7);
  19.   pinky.attach(8);
  20. }
  21.  
  22. void loop() {
  23.   if (bluetooth.available() > 0) {
  24.     char received = bluetooth.read();
  25.     if (received == '0') {
  26.       thumb.write(0);
  27.       pinky.write(0);
  28.       ring.write(0);
  29.       middle.write(0);
  30.       index.write(0);
  31.     } else if (received == '1') {
  32.       index.write(90);
  33.       pinky.write(0);
  34.       ring.write(0);
  35.       middle.write(0);
  36.       thumb.write(0);
  37.     } else if (received == '2') {
  38.       index.write(90);
  39.       middle.write(90);
  40.       pinky.write(0);
  41.       ring.write(0);
  42.       thumb.write(0);
  43.     } else if (received == '3') {
  44.       index.write(90);
  45.       middle.write(90);
  46.       ring.write(90);
  47.       pinky.write(0);
  48.       thumb.write(0);
  49.     } else if (received == '4') {
  50.       index.write(90);
  51.       middle.write(90);
  52.       ring.write(90);
  53.       pinky.write(90);
  54.       thumb.write(0);
  55.     } else if (received == '5') {
  56.       index.write(90);
  57.       middle.write(90);
  58.       ring.write(90);
  59.       pinky.write(90);
  60.       thumb.write(90);
  61.     }
  62.   }
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement