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: "Digital Output Setup"
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2024-02-11 14:27:54
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Develop an Arduino project for an H24 clock with */
- /* three timed outputs. The outputs should turn on */
- /* and off at specific times. */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* For example, at 11:30, output 1 should turn on for */
- /* 30 seconds and then turn off. At 11:45, output 2 */
- /* should turn on for 30 seconds and then turn off. */
- /* At 12:00, output 3 should turn on for 30 seconds */
- /* and then turn off. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <Sodaq_DS3231.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup();
- void loop();
- void updateOutputs();
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t Output1_PIN_D2 = 2;
- const uint8_t Output2_PIN_D3 = 3;
- const uint8_t Output3_PIN_D4 = 4;
- /***** DEFINITION OF I2C PINS *****/
- const uint8_t Rtc_PIN_SDA_A4 = A4;
- const uint8_t Rtc_PIN_SCL_A5 = A5;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool Output1_PIN_D2_rawData = 0;
- bool Output2_PIN_D3_rawData = 0;
- bool Output3_PIN_D4_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float Output1_PIN_D2_phyData = 0.0;
- float Output2_PIN_D3_phyData = 0.0;
- float Output3_PIN_D4_phyData = 0.0;
- void setup()
- {
- // put your setup code here, to run once:
- pinMode(Output1_PIN_D2, OUTPUT);
- pinMode(Output2_PIN_D3, OUTPUT);
- pinMode(Output3_PIN_D4, OUTPUT);
- // Initialize I2C
- Wire.begin();
- // Set initial raw data values for outputs
- Output1_PIN_D2_rawData = 0;
- Output2_PIN_D3_rawData = 0;
- Output3_PIN_D4_rawData = 0;
- // Update output pins
- updateOutputs();
- }
- void loop()
- {
- // put your main code here, to run repeatedly:
- // Refresh output data
- updateOutputs();
- // Check current time and update output pins accordingly
- DateTime now = rtc.now();
- int currentMinute = now.minute();
- int currentHour = now.hour();
- if (currentHour == 11 && currentMinute == 30)
- {
- Output1_PIN_D2_rawData = 1;
- delay(30000); // Wait for 30 seconds
- Output1_PIN_D2_rawData = 0;
- }
- else if (currentHour == 11 && currentMinute == 45)
- {
- Output2_PIN_D3_rawData = 1;
- delay(30000); // Wait for 30 seconds
- Output2_PIN_D3_rawData = 0;
- }
- else if (currentHour == 12 && currentMinute == 0)
- {
- Output3_PIN_D4_rawData = 1;
- delay(30000); // Wait for 30 seconds
- Output3_PIN_D4_rawData = 0;
- }
- delay(1000); // Wait for 1 second
- }
- void updateOutputs()
- {
- digitalWrite(Output1_PIN_D2, Output1_PIN_D2_rawData);
- digitalWrite(Output2_PIN_D3, Output2_PIN_D3_rawData);
- digitalWrite(Output3_PIN_D4, Output3_PIN_D4_rawData);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement