Advertisement
pleasedontcode

IoT Trigger rev_01

Aug 14th, 2024
474
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: IoT Trigger
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-08-14 14:01:07
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Implement a button press detection system using */
  21.     /* the EasyButton library to trigger actions in the */
  22.     /* IoTController, ensuring seamless integration with */
  23.     /* connected devices and user-friendly interaction. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  28. #include <IoTController.h>  //https://github.com/AndresDuran53/zarus-network-controller
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t button_PushButton_PIN_D2 = 2;
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. // Create an instance of EasyButton for the push button
  39. EasyButton button(button_PushButton_PIN_D2); // Initialize EasyButton with the pin number
  40.  
  41. // Create an instance of IoTController
  42. IoTController iotController("button-controller", 1); // Initialize IoTController with a name and number of data points
  43.  
  44. /****** FUNCTION DEFINITIONS *****/
  45. // Callback function to be called when the button is pressed
  46. void onButtonPressed() {
  47.     Serial.println("Button pressed! Triggering IoT action.");
  48.     // Here you can add code to trigger actions in the IoTController
  49.     // For example, you can send a message or change a state
  50.     iotController.addCommonData("button_state", "boolean", 1, "true", "bool", nullptr); // Example of adding data
  51. }
  52.  
  53. void setup(void)
  54. {
  55.     // put your setup code here, to run once:
  56.     pinMode(button_PushButton_PIN_D2, INPUT_PULLUP); // Set the button pin as input with pull-up resistor
  57.  
  58.     // Initialize Serial for debugging purposes
  59.     Serial.begin(115200);
  60.     Serial.println();
  61.     Serial.println(">>> EasyButton example <<<");
  62.  
  63.     // Initialize the button
  64.     button.begin(); // Call begin() to initialize the button
  65.     button.onPressed(onButtonPressed); // Attach the callback function for button press
  66.  
  67.     // Initialize IoTController
  68.     iotController.setup(); // Call setup() to initialize the IoTController
  69. }
  70.  
  71. void loop(void)
  72. {
  73.     // Continuously read the status of the button
  74.     button.read(); // Update the button state
  75.  
  76.     // Call the loop function of IoTController
  77.     iotController.loop(); // Ensure IoTController processes its tasks
  78. }
  79.  
  80. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement