Advertisement
pleasedontcode

Scanner rev_30

Oct 16th, 2023
68
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: Scanner
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-10-16 14:54:14
  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. // Led turn off and on
  24.  
  25. /****** FUNCTION PROTOTYPES *****/
  26. void setup(void);
  27. void loop(void);
  28. void toggleLed();
  29.  
  30. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  31. const uint8_t button_PushButton_PIN_D2 = 2;
  32. const uint8_t led_PIN_D13 = 13;
  33.  
  34. // Create an instance of EasyButton
  35. EasyButton button(button_PushButton_PIN_D2);
  36.  
  37. void setup(void)
  38. {
  39.   // put your setup code here, to run once:
  40.   pinMode(led_PIN_D13, OUTPUT);
  41.  
  42.   // Initialize the button
  43.   button.begin();
  44.  
  45.   // Attach a callback function to the button's onPressed event
  46.   button.onPressed(toggleLed);
  47. }
  48.  
  49. void loop(void)
  50. {
  51.   // put your main code here, to run repeatedly:
  52.   // Update the button state
  53.   button.read();
  54. }
  55.  
  56. // Callback function to toggle the LED state
  57. void toggleLed()
  58. {
  59.   static bool ledState = false;
  60.  
  61.   // Toggle the LED state
  62.   ledState = !ledState;
  63.  
  64.   // Set the LED pin based on the new state
  65.   digitalWrite(led_PIN_D13, ledState);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement