Advertisement
pleasedontcode

Relay Control rev_01

Jun 26th, 2024
687
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 Control
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-06-27 03:23:23
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Automate plant watering using a relay module. */
  21.     /* Control two relay channels connected to digital */
  22.     /* pins D2 and D3 to manage water pumps. Ensure the */
  23.     /* system updates output states continuously in the */
  24.     /* loop function. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Relay.h>  //https://github.com/rafaelnsantos/Relay
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs(void);
  34.  
  35. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  36. const uint8_t relay_RelayModule_Signal_PIN_D2 = 2;
  37. const uint8_t relay_RelayModule_Signal_PIN_D3 = 3;
  38.  
  39. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  40. /***** used to store raw data *****/
  41. bool relay_RelayModule_Signal_PIN_D2_rawData = 0;
  42. bool relay_RelayModule_Signal_PIN_D3_rawData = 0;
  43.  
  44. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  45. /***** used to store data after characteristic curve transformation *****/
  46. float relay_RelayModule_Signal_PIN_D2_phyData = 0.0;
  47. float relay_RelayModule_Signal_PIN_D3_phyData = 0.0;
  48.  
  49. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  50. Relay relay1(relay_RelayModule_Signal_PIN_D2, true); // Initialize relay on pin 2, Normally Open
  51. Relay relay2(relay_RelayModule_Signal_PIN_D3, true); // Initialize relay on pin 3, Normally Open
  52.  
  53. void setup(void)
  54. {
  55.     // put your setup code here, to run once:
  56.  
  57.     relay1.begin(); // Initialize the pin for relay1
  58.     relay2.begin(); // Initialize the pin for relay2
  59. }
  60.  
  61. void loop(void)
  62. {
  63.     // put your main code here, to run repeatedly:
  64.  
  65.     updateOutputs(); // Refresh output data
  66. }
  67.  
  68. void updateOutputs()
  69. {
  70.     // Update the state of relay1
  71.     if (relay_RelayModule_Signal_PIN_D2_rawData)
  72.         relay1.turnOn();
  73.     else
  74.         relay1.turnOff();
  75.  
  76.     // Update the state of relay2
  77.     if (relay_RelayModule_Signal_PIN_D3_rawData)
  78.         relay2.turnOn();
  79.     else
  80.         relay2.turnOff();
  81. }
  82.  
  83. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement