Advertisement
pleasedontcode

"Relay Control" rev_01

May 28th, 2024
582
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: ESP32 DevKit V1
  14.     - Source Code created on: 2024-05-28 09:48:47
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Designer home automation system in which the ESP */
  21.     /* 32 is able to control 9 relays with using ESP */
  22.     /* RainMaker application and from also control by */
  23.     /* manual switches. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <Relay.h>  //https://github.com/rafaelnsantos/Relay
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32. void updateOutputs(void);
  33.  
  34. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  35. const uint8_t Relaymodule_RelayModule_Signal_PIN_D4  = 4;
  36. const uint8_t Relaymodule_RelayModule_Signal_PIN_D13 = 13;
  37. const uint8_t Relaymodule_RelayModule_Signal_PIN_D14 = 14;
  38. const uint8_t Relaymodule_RelayModule_Signal_PIN_D15 = 15;
  39. const uint8_t Relaymodule_RelayModule_Signal_PIN_D16 = 16;
  40. const uint8_t Relaymodule_RelayModule_Signal_PIN_D17 = 17;
  41. const uint8_t Relaymodule_RelayModule_Signal_PIN_D18 = 18;
  42. const uint8_t Relaymodule_RelayModule_Signal_PIN_D19 = 19;
  43. const uint8_t Relaymodule_RelayModule_Signal_PIN_D21 = 21;
  44.  
  45. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  46. /***** used to store raw data *****/
  47. bool Relaymodule_RelayModule_Signal_PIN_D4_rawData  = 0;
  48. bool Relaymodule_RelayModule_Signal_PIN_D13_rawData = 0;
  49. bool Relaymodule_RelayModule_Signal_PIN_D14_rawData = 0;
  50. bool Relaymodule_RelayModule_Signal_PIN_D15_rawData = 0;
  51. bool Relaymodule_RelayModule_Signal_PIN_D16_rawData = 0;
  52. bool Relaymodule_RelayModule_Signal_PIN_D17_rawData = 0;
  53. bool Relaymodule_RelayModule_Signal_PIN_D18_rawData = 0;
  54. bool Relaymodule_RelayModule_Signal_PIN_D19_rawData = 0;
  55. bool Relaymodule_RelayModule_Signal_PIN_D21_rawData = 0;
  56.  
  57. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  58. /***** used to store data after characteristic curve transformation *****/
  59. float Relaymodule_RelayModule_Signal_PIN_D4_phyData  = 0.0;
  60. float Relaymodule_RelayModule_Signal_PIN_D13_phyData = 0.0;
  61. float Relaymodule_RelayModule_Signal_PIN_D14_phyData = 0.0;
  62. float Relaymodule_RelayModule_Signal_PIN_D15_phyData = 0.0;
  63. float Relaymodule_RelayModule_Signal_PIN_D16_phyData = 0.0;
  64. float Relaymodule_RelayModule_Signal_PIN_D17_phyData = 0.0;
  65. float Relaymodule_RelayModule_Signal_PIN_D18_phyData = 0.0;
  66. float Relaymodule_RelayModule_Signal_PIN_D19_phyData = 0.0;
  67. float Relaymodule_RelayModule_Signal_PIN_D21_phyData = 0.0;
  68.  
  69. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  70. Relay relayD4(Relaymodule_RelayModule_Signal_PIN_D4, true);   // Initialize relay on pin 4, Normally Open
  71. Relay relayD13(Relaymodule_RelayModule_Signal_PIN_D13, true); // Initialize relay on pin 13, Normally Open
  72. Relay relayD14(Relaymodule_RelayModule_Signal_PIN_D14, true); // Initialize relay on pin 14, Normally Open
  73. Relay relayD15(Relaymodule_RelayModule_Signal_PIN_D15, true); // Initialize relay on pin 15, Normally Open
  74. Relay relayD16(Relaymodule_RelayModule_Signal_PIN_D16, true); // Initialize relay on pin 16, Normally Open
  75. Relay relayD17(Relaymodule_RelayModule_Signal_PIN_D17, true); // Initialize relay on pin 17, Normally Open
  76. Relay relayD18(Relaymodule_RelayModule_Signal_PIN_D18, true); // Initialize relay on pin 18, Normally Open
  77. Relay relayD19(Relaymodule_RelayModule_Signal_PIN_D19, true); // Initialize relay on pin 19, Normally Open
  78. Relay relayD21(Relaymodule_RelayModule_Signal_PIN_D21, true); // Initialize relay on pin 21, Normally Open
  79.  
  80. void setup(void)
  81. {
  82.   // put your setup code here, to run once:
  83.  
  84.   relayD4.begin();  // Initialize the relay on pin 4
  85.   relayD13.begin(); // Initialize the relay on pin 13
  86.   relayD14.begin(); // Initialize the relay on pin 14
  87.   relayD15.begin(); // Initialize the relay on pin 15
  88.   relayD16.begin(); // Initialize the relay on pin 16
  89.   relayD17.begin(); // Initialize the relay on pin 17
  90.   relayD18.begin(); // Initialize the relay on pin 18
  91.   relayD19.begin(); // Initialize the relay on pin 19
  92.   relayD21.begin(); // Initialize the relay on pin 21
  93. }
  94.  
  95. void loop(void)
  96. {
  97.   // put your main code here, to run repeatedly:
  98.  
  99.   updateOutputs(); // Refresh output data
  100. }
  101.  
  102. void updateOutputs()
  103. {
  104.   // Update the state of each relay based on the raw data
  105.   if (Relaymodule_RelayModule_Signal_PIN_D4_rawData)
  106.     relayD4.turnOn();
  107.   else
  108.     relayD4.turnOff();
  109.  
  110.   if (Relaymodule_RelayModule_Signal_PIN_D13_rawData)
  111.     relayD13.turnOn();
  112.   else
  113.     relayD13.turnOff();
  114.  
  115.   if (Relaymodule_RelayModule_Signal_PIN_D14_rawData)
  116.     relayD14.turnOn();
  117.   else
  118.     relayD14.turnOff();
  119.  
  120.   if (Relaymodule_RelayModule_Signal_PIN_D15_rawData)
  121.     relayD15.turnOn();
  122.   else
  123.     relayD15.turnOff();
  124.  
  125.   if (Relaymodule_RelayModule_Signal_PIN_D16_rawData)
  126.     relayD16.turnOn();
  127.   else
  128.     relayD16.turnOff();
  129.  
  130.   if (Relaymodule_RelayModule_Signal_PIN_D17_rawData)
  131.     relayD17.turnOn();
  132.   else
  133.     relayD17.turnOff();
  134.  
  135.   if (Relaymodule_RelayModule_Signal_PIN_D18_rawData)
  136.     relayD18.turnOn();
  137.   else
  138.     relayD18.turnOff();
  139.  
  140.   if (Relaymodule_RelayModule_Signal_PIN_D19_rawData)
  141.     relayD19.turnOn();
  142.   else
  143.     relayD19.turnOff();
  144.  
  145.   if (Relaymodule_RelayModule_Signal_PIN_D21_rawData)
  146.     relayD21.turnOn();
  147.   else
  148.     relayD21.turnOff();
  149. }
  150.  
  151. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement