Advertisement
pleasedontcode

Servo Sweep rev_01

Jul 2nd, 2024
805
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 Sweep
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-07-02 21:38:55
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Design an Arduino system to manage two SG90 */
  21.     /* servomotors using PWM on pins D3 and D5. Leverage */
  22.     /* the Servo and ArduinoLearningBoard libraries. */
  23.     /* Include setup for pin initialization and a loop */
  24.     /* function to handle continuous motor position */
  25.     /* updates. */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #define USE_ALB_Servo  // Define to include the Servo functions of the ArduinoLearningBoard Library
  30. #include "ArduinoLearningBoard.h"  // Include the main ArduinoLearningBoard library
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35.  
  36. /***** DEFINITION OF PWM OUTPUT PINS *****/
  37. const uint8_t sg90_Servomotor_PWMSignal_PIN_D3 = 3;
  38. const uint8_t sg90_Servomotor_PWMSignal_PIN_D5 = 5;
  39.  
  40. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  41. /***** used to store raw data *****/
  42. uint8_t sg90_Servomotor_PWMSignal_PIN_D3_rawData = 0;
  43. uint8_t sg90_Servomotor_PWMSignal_PIN_D5_rawData = 0;
  44.  
  45. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  46. /***** used to store data after characteristic curve transformation *****/
  47. float sg90_Servomotor_PWMSignal_PIN_D3_phyData = 0.0;
  48. float sg90_Servomotor_PWMSignal_PIN_D5_phyData = 0.0;
  49.  
  50. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  51. Servo servo1;  // Create a Servo object for the first servo
  52. Servo servo2;  // Create a Servo object for the second servo
  53.  
  54. void setup(void)
  55. {
  56.   // put your setup code here, to run once:
  57.  
  58.   pinMode(sg90_Servomotor_PWMSignal_PIN_D3, OUTPUT);
  59.   pinMode(sg90_Servomotor_PWMSignal_PIN_D5, OUTPUT);
  60.  
  61.   servo1.attach(sg90_Servomotor_PWMSignal_PIN_D3);  // Attach the first servo to pin D3
  62.   servo2.attach(sg90_Servomotor_PWMSignal_PIN_D5);  // Attach the second servo to pin D5
  63. }
  64.  
  65. void loop(void)
  66. {
  67.   // put your main code here, to run repeatedly:
  68.  
  69.   // Sweep the first servo
  70.   for (int pos = 0; pos <= 180; pos += 1) {
  71.     servo1.write(pos);  // Move the first servo to the current position
  72.     delay(15);  // Wait for 15 milliseconds
  73.   }
  74.   for (int pos = 180; pos >= 0; pos -= 1) {
  75.     servo1.write(pos);  // Move the first servo to the current position
  76.     delay(15);  // Wait for 15 milliseconds
  77.   }
  78.  
  79.   // Sweep the second servo
  80.   for (int pos = 0; pos <= 180; pos += 1) {
  81.     servo2.write(pos);  // Move the second servo to the current position
  82.     delay(15);  // Wait for 15 milliseconds
  83.   }
  84.   for (int pos = 180; pos >= 0; pos -= 1) {
  85.     servo2.write(pos);  // Move the second servo to the current position
  86.     delay(15);  // Wait for 15 milliseconds
  87.   }
  88. }
  89.  
  90. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement