Advertisement
pleasedontcode

"Relay Logic" rev_02

Apr 4th, 2024
128
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: "Relay Logic"
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2024-04-04 23:49:01
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Turns Relay on at 8:00 every morning and turn */
  21.     /* itself off after 3min or if the water level goes */
  22.     /* below 10%. */
  23. /****** SYSTEM REQUIREMENT 2 *****/
  24.     /* Turns the nano RBG light to blue when relay is on */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Arduino.h>
  29.  
  30. /****** FUNCTION PROTOTYPES ******/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs(void);
  34. void turnOnRelay(void);
  35. void turnOffRelay(void);
  36.  
  37. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  38. const uint8_t Water_Level_PIN_D2 = 2;
  39.  
  40. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  41. const uint8_t Relay_PIN_D4 = 4;
  42. const uint8_t RGB_LIGHT_PIN_D7 = 7;
  43.  
  44. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  45. /***** used to store raw data *****/
  46. bool Relay_PIN_D4_rawData = false;
  47.  
  48. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  49. /***** used to store data after characteristic curve transformation *****/
  50. float Relay_PIN_D4_phyData = 0.0;
  51.  
  52. void setup(void)
  53. {
  54.   // put your setup code here, to run once:
  55.  
  56.   // Setup digital input pins
  57.   pinMode(Water_Level_PIN_D2, INPUT);
  58.  
  59.   // Setup digital output pins
  60.   pinMode(Relay_PIN_D4, OUTPUT);
  61.   pinMode(RGB_LIGHT_PIN_D7, OUTPUT);
  62.  
  63.   // Turn off the relay initially
  64.   turnOffRelay();
  65. }
  66.  
  67. void loop(void)
  68. {
  69.   // put your main code here, to run repeatedly:
  70.  
  71.   // Check if it's 8:00 AM
  72.   if (getCurrentHour() == 8 && getCurrentMinute() == 0)
  73.   {
  74.     // Turn on the relay
  75.     turnOnRelay();
  76.   }
  77.  
  78.   // Check if the water level goes below 10%
  79.   if (readWaterLevel() < 10)
  80.   {
  81.     // Turn off the relay
  82.     turnOffRelay();
  83.   }
  84.  
  85.   // Turn the nano RGB light to blue when relay is on
  86.   if (Relay_PIN_D4_rawData)
  87.   {
  88.     digitalWrite(RGB_LIGHT_PIN_D7, HIGH); // Turn on the RGB light
  89.   }
  90.   else
  91.   {
  92.     digitalWrite(RGB_LIGHT_PIN_D7, LOW); // Turn off the RGB light
  93.   }
  94.  
  95.   delay(1000); // Delay for 1 second before checking conditions again
  96. }
  97.  
  98. void updateOutputs(void)
  99. {
  100.   digitalWrite(Relay_PIN_D4, Relay_PIN_D4_rawData);
  101. }
  102.  
  103. void turnOnRelay(void)
  104. {
  105.   Relay_PIN_D4_rawData = true;
  106.   updateOutputs();
  107. }
  108.  
  109. void turnOffRelay(void)
  110. {
  111.   Relay_PIN_D4_rawData = false;
  112.   updateOutputs();
  113. }
  114.  
  115. int getCurrentHour(void)
  116. {
  117.   // Implement code to get current hour value from the system clock
  118.   // Return the current hour
  119.   return 8; // Stub return value for testing, replace with actual code
  120. }
  121.  
  122. int getCurrentMinute(void)
  123. {
  124.   // Implement code to get current minute value from the system clock
  125.   // Return the current minute
  126.   return 0; // Stub return value for testing, replace with actual code
  127. }
  128.  
  129. float readWaterLevel(void)
  130. {
  131.   // Implement code to read the water level from the sensor
  132.   // Return the water level value in percentage
  133.   return 5.0; // Stub return value for testing, replace with actual code
  134. }
  135.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement