Advertisement
pleasedontcode

Tech_arduinov1 rev_28

Oct 14th, 2023
110
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: Tech_arduinov1
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-10-14 21:41:22
  15.     - Source Code generated by: AlexWind
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <EasyButton.h>
  21.  
  22. /****** SYSTEM REQUIREMENT 1 *****/
  23. /* turn on the light when you click the button */
  24.  
  25. /****** FUNCTION PROTOTYPES *****/
  26. void setup(void);
  27. void loop(void);
  28.  
  29. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  30. const uint8_t BUTTON_PIN = 2;
  31. const uint8_t LED_PIN = LED_BUILTIN;
  32.  
  33. // Initialize the button object
  34. EasyButton button(BUTTON_PIN);
  35.  
  36. void setup(void)
  37. {
  38.   // put your setup code here, to run once:
  39.   pinMode(LED_PIN, OUTPUT);
  40.  
  41.   // Define the callback function to turn on the light when the button is pressed
  42.   button.onPressed([]() {
  43.     digitalWrite(LED_PIN, HIGH);
  44.   });
  45.  
  46.   // Begin the button object
  47.   button.begin();
  48. }
  49.  
  50. void loop(void)
  51. {
  52.   // put your main code here, to run repeatedly:
  53.   // Update the button state
  54.   button.read();
  55.  
  56.   // Check if the button is pressed
  57.   if (button.isPressed()) {
  58.     // Call the callback function to turn on the light
  59.     digitalWrite(LED_PIN, HIGH);
  60.   }
  61.  
  62.   // Check if the button is released
  63.   if (button.isReleased()) {
  64.     // Call the callback function to turn off the light
  65.     digitalWrite(LED_PIN, LOW);
  66.   }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement