Advertisement
pleasedontcode

**Servo Control** rev_01

Nov 9th, 2024
81
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 NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-11-09 16:29:38
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* 3 servos will go up but 2 slower */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /* START CODE */
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Servo.h>  // Include the Servo library
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. // Create Servo objects
  33. Servo servo1;  // Fast servo
  34. Servo servo2;  // Slow servo 1
  35. Servo servo3;  // Slow servo 2
  36.  
  37. void setup(void)
  38. {
  39.     // Attach servos to pins
  40.     servo1.attach(9);  // Attach fast servo to pin 9
  41.     servo2.attach(10); // Attach slow servo 1 to pin 10
  42.     servo3.attach(11); // Attach slow servo 2 to pin 11
  43. }
  44.  
  45. void loop(void)
  46. {
  47.     // Move the fast servo to 90 degrees
  48.     servo1.write(90);
  49.     delay(1000); // Wait for 1 second
  50.  
  51.     // Move the slow servos to 90 degrees
  52.     servo2.write(90);
  53.     servo3.write(90);
  54.     delay(2000); // Wait for 2 seconds to move slower
  55.  
  56.     // Move the servos back to 0 degrees
  57.     servo1.write(0);
  58.     delay(1000); // Wait for 1 second
  59.  
  60.     // Move the slow servos back to 0 degrees
  61.     servo2.write(0);
  62.     servo3.write(0);
  63.     delay(2000); // Wait for 2 seconds to move slower
  64. }
  65.  
  66. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement