Advertisement
pleasedontcode

Servo Control rev_01

Apr 27th, 2024
122
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-04-27 15:46:03
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* turn on for 30 sec then stop and repeat cycle */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Servo.h>  // https://github.com/arduino-libraries/Servo
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29. void updateOutputs(void); // Added function prototype for updateOutputs
  30.  
  31. /***** DEFINITION OF PWM OUTPUT PINS *****/
  32. const uint8_t Servo_Servomotor_PWMSignal_PIN_D3 = 3;
  33. const uint8_t Servo_Servomotor_PWMSignal_PIN_D5 = 5;
  34.  
  35. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  36. uint8_t Servo_Servomotor_PWMSignal_PIN_D3_rawData = 0;
  37. uint8_t Servo_Servomotor_PWMSignal_PIN_D5_rawData = 0;
  38.  
  39. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  40. float Servo_Servomotor_PWMSignal_PIN_D3_phyData = 0.0;
  41. float Servo_Servomotor_PWMSignal_PIN_D5_phyData = 0.0;
  42.  
  43. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  44. Servo myservo; // Initializing Servo library object
  45.  
  46. void setup(void)
  47. {
  48.   // put your setup code here, to run once:
  49.   pinMode(Servo_Servomotor_PWMSignal_PIN_D3, OUTPUT);
  50.   pinMode(Servo_Servomotor_PWMSignal_PIN_D5, OUTPUT);
  51.  
  52.   myservo.attach(Servo_Servomotor_PWMSignal_PIN_D3); // Attaching servo to pin D3
  53. }
  54.  
  55. void loop(void)
  56. {
  57.   // put your main code here, to run repeatedly:
  58.   updateOutputs(); // Refresh output data
  59.  
  60.   // System Requirement 1: Turn on for 30 sec then stop and repeat cycle
  61.   myservo.write(180); // Turn on the servo to its maximum position
  62.   delay(30000); // Wait for 30 seconds
  63.   myservo.write(0); // Stop the servo by setting it to its minimum position
  64.   delay(1000); // Wait for 1 second before repeating the cycle
  65. }
  66.  
  67. void updateOutputs()
  68. {
  69.   analogWrite(Servo_Servomotor_PWMSignal_PIN_D3, Servo_Servomotor_PWMSignal_PIN_D3_rawData);
  70.   analogWrite(Servo_Servomotor_PWMSignal_PIN_D5, Servo_Servomotor_PWMSignal_PIN_D5_rawData);
  71. }
  72.  
  73. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement