Advertisement
pleasedontcode

Remote rev_01

Oct 25th, 2023
50
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: Remote
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-10-25 14:28:00
  15.     - Source Code generated by: hetal
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <EasyButton.h>
  21.  
  22. /****** SYSTEM REQUIREMENT 1 *****/
  23. const uint8_t Relay_PIN = 3; // Pin for controlling the relay
  24. const uint8_t PushButton_PIN = 2; // Pin for the push button
  25.  
  26. EasyButton pushButton(PushButton_PIN); // Create an instance of the EasyButton library
  27.  
  28. void setup(void)
  29. {
  30.   pinMode(Relay_PIN, OUTPUT); // Set the relay pin as output
  31.   pushButton.begin(); // Initialize the push button
  32.  
  33.   // Attach a function to be called when the button is pressed
  34.   pushButton.onPressed([]() {
  35.     digitalWrite(Relay_PIN, !digitalRead(Relay_PIN)); // Toggle the relay state
  36.   });
  37. }
  38.  
  39. void loop(void)
  40. {
  41.   pushButton.read(); // Read the state of the push button
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement