Advertisement
pleasedontcode

Button LED rev_01

Apr 8th, 2024
91
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: Button LED
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-08 18:25:10
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* I have a push button to digital pin 4 and a led on */
  21.     /* pin 8. Pin 8 high turns on the light.    When the */
  22.     /* button is pressed once I want to turn light on. */
  23.     /* Holding the button will start running it and let */
  24.     /* it run as long as pr */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <EasyButton.h>
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t startButton_PushButton_PIN_D4 = 4;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t ledLight_LED_PIN_D8 = 8;
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. /***** used to store raw data *****/
  43. bool ledLight_LED_PIN_D8_rawData = LOW;
  44.  
  45. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  46. EasyButton startButton(startButton_PushButton_PIN_D4);
  47.  
  48. void setup(void)
  49. {
  50.   // put your setup code here, to run once:
  51.   pinMode(ledLight_LED_PIN_D8, OUTPUT);
  52.  
  53.   startButton.begin();
  54.   startButton.onPressed([]() {
  55.     ledLight_LED_PIN_D8_rawData = HIGH;
  56.   });
  57.  
  58.   Serial.begin(115200);
  59. }
  60.  
  61. void loop(void)
  62. {
  63.   // put your main code here, to run repeatedly:
  64.   updateOutputs(); // Refresh output data
  65.   startButton.read();
  66.  
  67.   if (startButton.isPressed()) {
  68.     digitalWrite(ledLight_LED_PIN_D8, HIGH);
  69.   } else {
  70.     digitalWrite(ledLight_LED_PIN_D8, LOW);
  71.   }
  72. }
  73.  
  74. void updateOutputs()
  75. {
  76.   digitalWrite(ledLight_LED_PIN_D8, ledLight_LED_PIN_D8_rawData);
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement