Advertisement
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: Servo Control
- - Source Code NOT compiled for: Arduino Mega
- - Source Code created on: 2024-06-19 07:27:25
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Develop a blind solar tracker system using DS3231 */
- /* RTC for timekeeping and Servo motors for panel */
- /* adjustment. Ensure precise control of servo */
- /* positions based on real-time data. Utilize I2C */
- /* communication for RTC and PWM signals for servos. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <DS3231.h> // https://github.com/NorthernWidget/DS3231
- #include <Servo.h> // https://github.com/arduino-libraries/Servo
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- /***** DEFINITION OF PWM OUTPUT PINS *****/
- const uint8_t servo1_Servomotor_PWMSignal_PIN_D2 = 2;
- const uint8_t servo2_Servomotor_PWMSignal_PIN_D3 = 3;
- /***** DEFINITION OF I2C PINS *****/
- const uint8_t RTC_DS3231_I2C_PIN_SDA_D20 = 20;
- const uint8_t RTC_DS3231_I2C_PIN_SCL_D21 = 21;
- const uint8_t RTC_DS3231_I2C_SLAVE_ADDRESS = 104;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- uint8_t servo1_Servomotor_PWMSignal_PIN_D2_rawData = 0;
- uint8_t servo2_Servomotor_PWMSignal_PIN_D3_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float servo1_Servomotor_PWMSignal_PIN_D2_phyData = 0.0;
- float servo2_Servomotor_PWMSignal_PIN_D3_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- DS3231 myRTC; // Initialize DS3231 object
- Servo servo1; // Initialize Servo object for servo1
- Servo servo2; // Initialize Servo object for servo2
- void setup(void)
- {
- // put your setup code here, to run once:
- Wire.begin();
- Serial.begin(57600);
- delay(500);
- Serial.println("Arduino Mega Ready!");
- // Attach the servo objects to the PWM pins
- servo1.attach(servo1_Servomotor_PWMSignal_PIN_D2);
- servo2.attach(servo2_Servomotor_PWMSignal_PIN_D3);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- // Example of reading time from DS3231 and printing it
- DateTime now = myRTC.now();
- Serial.print(now.year());
- Serial.print('/');
- Serial.print(now.month());
- Serial.print('/');
- Serial.print(now.day());
- Serial.print(' ');
- Serial.print(now.hour());
- Serial.print(':');
- Serial.print(now.minute());
- Serial.print(':');
- Serial.print(now.second());
- Serial.println();
- delay(1000); // Delay for 1 second
- }
- void updateOutputs()
- {
- // Write the raw data to the servos
- servo1.write(servo1_Servomotor_PWMSignal_PIN_D2_rawData);
- servo2.write(servo2_Servomotor_PWMSignal_PIN_D3_rawData);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement