Advertisement
pleasedontcode

"Real-Time Relay" rev_01

May 29th, 2024
602
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: "Real-Time Relay"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-05-29 20:43:54
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* یک سیستم کنترل رله را با یک دکمه روی پایه D2 طراحی */
  21.     /* کنید. رله را در تابع راه اندازی اولیه کنید و به */
  22.     /* طور مداوم وضعیت آن را در تابع حلقه بر اساس ورودی */
  23.     /* داده خام دکمه به روز کنید. */
  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 Button_PIN_D2 = 2; // Button connected to pin D2
  36. const uint8_t Relay_PIN = 3; // Relay connected to pin D3
  37.  
  38. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  39. /***** used to store raw data *****/
  40. bool Button_PIN_D2_rawData = 0;
  41.  
  42. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  43. /***** used to store data after characteristic curve transformation *****/
  44. float Button_PIN_D2_phyData = 0.0;
  45.  
  46. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  47. Relay light(Relay_PIN, true); // Initialize relay on pin 3, Normally Open
  48.  
  49. void setup(void)
  50. {
  51.     // put your setup code here, to run once:
  52.     pinMode(Button_PIN_D2, INPUT); // Initialize the button pin as input
  53.     light.begin(); // Initialize the relay pin
  54. }
  55.  
  56. void loop(void)
  57. {
  58.     // put your main code here, to run repeatedly:
  59.     updateOutputs(); // Refresh output data
  60. }
  61.  
  62. void updateOutputs()
  63. {
  64.     // Read the button state
  65.     Button_PIN_D2_rawData = digitalRead(Button_PIN_D2);
  66.  
  67.     // Update relay state based on button input
  68.     if (Button_PIN_D2_rawData)
  69.     {
  70.         light.turnOn(); // Turn relay on if button is pressed
  71.     }
  72.     else
  73.     {
  74.         light.turnOff(); // Turn relay off if button is not pressed
  75.     }
  76.  
  77.     // Get relay state and update raw data
  78.     Button_PIN_D2_rawData = light.getState();
  79.     digitalWrite(Relay_PIN, Button_PIN_D2_rawData);
  80. }
  81.  
  82. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement