Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Button Toggle
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2024-02-16 07:12:48
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The system shall control the blinking of a bulb */
- /* connected to pin D2 using a push button connected */
- /* to pin D3. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t bulb_PIN_D2 = 2;
- const uint8_t pushButton_PIN_D3 = 3;
- /****** DEFINITION OF LIBRARY CLASS INSTANCES*****/
- EasyButton pushButton(pushButton_PIN_D3);
- void setup(void)
- {
- // initialize the bulb pin as an output
- pinMode(bulb_PIN_D2, OUTPUT);
- // initialize the push button pin as an input with the internal pull-up resistor enabled
- pinMode(pushButton_PIN_D3, INPUT_PULLUP);
- // initialize the push button object
- pushButton.begin();
- }
- void loop(void)
- {
- // read the state of the push button
- pushButton.read();
- // check if the push button is pressed
- if (pushButton.isPressed())
- {
- // toggle the state of the bulb
- digitalWrite(bulb_PIN_D2, !digitalRead(bulb_PIN_D2));
- delay(200); // add a small delay to debounce the button
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement