Advertisement
pleasedontcode

Servo Control rev_02

Dec 28th, 2023
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Servo Control
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2023-12-28 06:14:52
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* i want to attach two servo to swap in opposite */
  21.     /* direction */
  22. /****** SYSTEM REQUIREMENT 2 *****/
  23.     /* i want to attach 8 servo to make a humanoid robot */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <Arduino.h>
  28. #include <Servo.h>
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** DEFINITION OF PWM OUTPUT PINS *****/
  35. const uint8_t servo1_PIN = 3;
  36. const uint8_t servo2_PIN = 5;
  37.  
  38. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  39. Servo servo1;
  40. Servo servo2;
  41. Servo servo3;
  42. Servo servo4;
  43. Servo servo5;
  44. Servo servo6;
  45. Servo servo7;
  46. Servo servo8;
  47.  
  48. void setup(void)
  49. {
  50.   // put your setup code here, to run once:
  51.   servo1.attach(servo1_PIN);
  52.   servo2.attach(servo2_PIN);
  53.  
  54.   // Attach additional servos for humanoid robot
  55.   servo3.attach(6);
  56.   servo4.attach(9);
  57.   servo5.attach(10);
  58.   servo6.attach(11);
  59.   servo7.attach(12);
  60.   servo8.attach(13);
  61. }
  62.  
  63. void loop(void)
  64. {
  65.   // put your main code here, to run repeatedly:
  66.  
  67.   /****** SYSTEM REQUIREMENT 1 *****/
  68.   // Swap servo1 and servo2 in opposite directions
  69.   for (int pos = 0; pos <= 180; pos += 1) {
  70.     servo1.write(pos);
  71.     servo2.write(180 - pos);
  72.     delay(15);
  73.   }
  74.  
  75.   /****** SYSTEM REQUIREMENT 2 *****/
  76.   // Move all the servos for the humanoid robot
  77.   for (int pos = 0; pos <= 180; pos += 1) {
  78.     servo3.write(pos);
  79.     servo4.write(pos);
  80.     servo5.write(pos);
  81.     servo6.write(pos);
  82.     servo7.write(pos);
  83.     servo8.write(pos);
  84.     delay(15);
  85.   }
  86.  
  87.   for (int pos = 180; pos >= 0; pos -= 1) {
  88.     servo3.write(pos);
  89.     servo4.write(pos);
  90.     servo5.write(pos);
  91.     servo6.write(pos);
  92.     servo7.write(pos);
  93.     servo8.write(pos);
  94.     delay(15);
  95.   }
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement