Advertisement
pleasedontcode

"Digital Output Setup" rev_02

Feb 11th, 2024
82
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: "Digital Output Setup"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-02-11 14:27:54
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop an Arduino project for an H24 clock with */
  21.     /* three timed outputs. The outputs should turn on */
  22.     /* and off at specific times. */
  23. /****** SYSTEM REQUIREMENT 2 *****/
  24.     /* For example, at 11:30, output 1 should turn on for */
  25.     /* 30 seconds and then turn off. At 11:45, output 2 */
  26.     /* should turn on for 30 seconds and then turn off. */
  27.     /* At 12:00, output 3 should turn on for 30 seconds */
  28.     /* and then turn off. */
  29. /****** END SYSTEM REQUIREMENTS *****/
  30.  
  31. /****** DEFINITION OF LIBRARIES *****/
  32. #include <Wire.h>
  33. #include <Sodaq_DS3231.h>
  34.  
  35. /****** FUNCTION PROTOTYPES *****/
  36. void setup();
  37. void loop();
  38. void updateOutputs();
  39.  
  40. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  41. const uint8_t Output1_PIN_D2 = 2;
  42. const uint8_t Output2_PIN_D3 = 3;
  43. const uint8_t Output3_PIN_D4 = 4;
  44.  
  45. /***** DEFINITION OF I2C PINS *****/
  46. const uint8_t Rtc_PIN_SDA_A4 = A4;
  47. const uint8_t Rtc_PIN_SCL_A5 = A5;
  48.  
  49. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  50. /***** used to store raw data *****/
  51. bool Output1_PIN_D2_rawData = 0;
  52. bool Output2_PIN_D3_rawData = 0;
  53. bool Output3_PIN_D4_rawData = 0;
  54.  
  55. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  56. /***** used to store data after characteristic curve transformation *****/
  57. float Output1_PIN_D2_phyData = 0.0;
  58. float Output2_PIN_D3_phyData = 0.0;
  59. float Output3_PIN_D4_phyData = 0.0;
  60.  
  61. void setup()
  62. {
  63.   // put your setup code here, to run once:
  64.   pinMode(Output1_PIN_D2, OUTPUT);
  65.   pinMode(Output2_PIN_D3, OUTPUT);
  66.   pinMode(Output3_PIN_D4, OUTPUT);
  67.  
  68.   // Initialize I2C
  69.   Wire.begin();
  70.  
  71.   // Set initial raw data values for outputs
  72.   Output1_PIN_D2_rawData = 0;
  73.   Output2_PIN_D3_rawData = 0;
  74.   Output3_PIN_D4_rawData = 0;
  75.  
  76.   // Update output pins
  77.   updateOutputs();
  78. }
  79.  
  80. void loop()
  81. {
  82.   // put your main code here, to run repeatedly:
  83.  
  84.   // Refresh output data
  85.   updateOutputs();
  86.  
  87.   // Check current time and update output pins accordingly
  88.   DateTime now = rtc.now();
  89.   int currentMinute = now.minute();
  90.   int currentHour = now.hour();
  91.  
  92.   if (currentHour == 11 && currentMinute == 30)
  93.   {
  94.     Output1_PIN_D2_rawData = 1;
  95.     delay(30000); // Wait for 30 seconds
  96.     Output1_PIN_D2_rawData = 0;
  97.   }
  98.   else if (currentHour == 11 && currentMinute == 45)
  99.   {
  100.     Output2_PIN_D3_rawData = 1;
  101.     delay(30000); // Wait for 30 seconds
  102.     Output2_PIN_D3_rawData = 0;
  103.   }
  104.   else if (currentHour == 12 && currentMinute == 0)
  105.   {
  106.     Output3_PIN_D4_rawData = 1;
  107.     delay(30000); // Wait for 30 seconds
  108.     Output3_PIN_D4_rawData = 0;
  109.   }
  110.   delay(1000); // Wait for 1 second
  111. }
  112.  
  113. void updateOutputs()
  114. {
  115.   digitalWrite(Output1_PIN_D2, Output1_PIN_D2_rawData);
  116.   digitalWrite(Output2_PIN_D3, Output2_PIN_D3_rawData);
  117.   digitalWrite(Output3_PIN_D4, Output3_PIN_D4_rawData);
  118. }
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement