pleasedontcode

Relay Control rev_01

Jul 15th, 2025
177
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: 2025-07-15 18:42:53
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Génère un code Arduino pour un ESP32 (ESP- */
  21.     /* WROOM-32) utilisant un module MAX485 pour lire les */
  22.     /* valeurs DMX des canaux 1, 2 et 3, en utilisant la */
  23.     /* bibliothèque DMXSerial compatible avec ESP32. */
  24.     /* Inclut la configuration des broches UART. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /* START CODE */
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <Relay.h>
  30. #include <DMXSerial.h>
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void updateOutputs(void);
  36.  
  37. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  38. const uint8_t myRelayModule_RelayModule_Signal_PIN_D4 = 4;
  39.  
  40. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  41. /***** used to store raw data *****/
  42. bool myRelayModule_RelayModule_Signal_PIN_D4_rawData = 0;
  43.  
  44. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  45. /***** used to store data after characteristic curve transformation *****/
  46. float myRelayModule_RelayModule_Signal_PIN_D4_phyData = 0.0;
  47.  
  48. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  49. Relay relayDevice(2, false); // Relay on pin 2, normally closed
  50.  
  51. void setup(void)
  52. {
  53.   // Initialize relay pin
  54.   pinMode(myRelayModule_RelayModule_Signal_PIN_D4, OUTPUT);
  55.  
  56.   // Initialize DMXSerial on UART1 for MAX485 communication
  57.   DMXSerial.init(1);
  58. }
  59.  
  60. void loop(void)
  61. {
  62.   // Refresh output data
  63.   updateOutputs();
  64.  
  65.   // Read DMX channels 1, 2, and 3
  66.   int channel1 = DMXSerial.read(1);
  67.   int channel2 = DMXSerial.read(2);
  68.   int channel3 = DMXSerial.read(3);
  69.  
  70.   // Map DMX channel 1 to relay raw data (HIGH if value > 127, else LOW)
  71.   myRelayModule_RelayModule_Signal_PIN_D4_rawData = (channel1 > 127) ? HIGH : LOW;
  72. }
  73.  
  74. void updateOutputs()
  75. {
  76.   // Write relay state to the output pin
  77.   digitalWrite(myRelayModule_RelayModule_Signal_PIN_D4, myRelayModule_RelayModule_Signal_PIN_D4_rawData);
  78. }
  79.  
Advertisement
Add Comment
Please, Sign In to add comment