Advertisement
pleasedontcode

"Servo Swap" rev_01

Dec 28th, 2023
80
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 Swap"
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2023-12-28 06:12:16
  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. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h>
  26. #include <Servo.h>
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF PWM OUTPUT PINS *****/
  33. const uint8_t servo1_PIN = 3;
  34. const uint8_t servo2_PIN = 5;
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37. Servo servo1;
  38. Servo servo2;
  39.  
  40. void setup(void)
  41. {
  42.   // put your setup code here, to run once:
  43.   pinMode(servo1_PIN, OUTPUT);
  44.   pinMode(servo2_PIN, OUTPUT);
  45.  
  46.   servo1.attach(servo1_PIN); // Attaching servo1 to pin D3
  47.   servo2.attach(servo2_PIN); // Attaching servo2 to pin D5
  48. }
  49.  
  50. void loop(void)
  51. {
  52.   // put your main code here, to run repeatedly:
  53.  
  54.   // Swap the servo positions in opposite directions
  55.   for (int angle = 0; angle <= 180; angle++) {
  56.     servo1.write(angle);
  57.     servo2.write(180 - angle);
  58.     delay(15); // Adjust the delay according to your requirements
  59.   }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement