Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Scheduled Servo
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-08-29 07:24:02
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* rotating at 1pm */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Servo.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void rotateServoSweep(void); // new: performs a complete 0-180-0 sweep
- /***** DEFINITION OF PWM OUTPUT PINS *****/
- const uint8_t servoo_Servomotor_PWMSignal_PIN_D3 = 3;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
- Servo servomotor; // Servo object to control the PWM pin
- // Timekeeping (software clock)
- unsigned long bootMillis; // time reference from startup
- int lastRotatedDay = -1; // last day when the 1pm rotation occurred
- void rotateServoSweep(void)
- {
- // Rotates servo from 0 to 180 and back
- for (int pos = 0; pos <= 180; pos++) {
- servomotor.write(pos);
- delay(15);
- }
- for (int pos = 180; pos >= 0; pos--) {
- servomotor.write(pos);
- delay(15);
- }
- }
- void setup(void)
- {
- // put your setup code here, to run once:
- // Attach the servo to the PWM pin
- servomotor.attach(servoo_Servomotor_PWMSignal_PIN_D3);
- // Optional: set an initial position
- servomotor.write(90);
- // Initialize software clock reference
- bootMillis = millis();
- // Note: When using the Servo library, explicit pinMode is not required.
- // If you want to force a digital pin mode, you could uncomment the line below,
- // but it's generally unnecessary with Servo.attach().
- // pinMode(servoo_Servomotor_PWMSignal_PIN_D3, OUTPUT);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- // Compute a simple software time (UTC-like) starting from boot
- unsigned long elapsedSec = (millis() - (unsigned long)bootMillis) / 1000;
- int currentSecond = elapsedSec % 60;
- int currentMinute = (elapsedSec / 60) % 60;
- int currentHour = (elapsedSec / 3600) % 24;
- int currentDay = elapsedSec / 86400;
- // Trigger rotation at 13:00:00 once per day
- if (currentDay != lastRotatedDay && currentHour == 13 && currentMinute == 0 && currentSecond == 0) {
- rotateServoSweep();
- lastRotatedDay = currentDay;
- }
- else if (currentDay != lastRotatedDay) {
- // Before 1pm (or any other time before rotation), perform a small idle sweep to keep motion visible
- for (int pos = 0; pos <= 60; pos++) {
- servomotor.write(pos);
- delay(5);
- }
- for (int pos = 60; pos >= 0; pos--) {
- servomotor.write(pos);
- delay(5);
- }
- }
- else {
- // Already rotated today; idle to avoid a tight loop
- delay(100);
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment