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 Control
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2024-03-27 15:26:08
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Menghidupkan LED, ketika tombol ditekan */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* Menghidupkan LED, ketika tombol ditekan */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Power_PushButton_PIN_D2 = 2;
- const uint8_t Power_PushButton_PIN_D3 = 3;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- EasyButton Power_PushButton_D2(Power_PushButton_PIN_D2);
- EasyButton Power_PushButton_D3(Power_PushButton_PIN_D3);
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- const uint8_t LED_PIN_D4 = 4; // Define the pin for the LED
- bool isButtonD2Pressed = false; // Flag to keep track of button D2 state
- /****** SYSTEM REQUIREMENT 2 *****/
- const uint8_t LED_PIN_D5 = 5; // Define the pin for the LED
- bool isButtonD3Pressed = false; // Flag to keep track of button D3 state
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(Power_PushButton_PIN_D2, INPUT_PULLUP);
- pinMode(Power_PushButton_PIN_D3, INPUT_PULLUP);
- Power_PushButton_D2.begin();
- Power_PushButton_D3.begin();
- /****** SYSTEM REQUIREMENT 1 *****/
- pinMode(LED_PIN_D4, OUTPUT); // Set the LED pin as output
- /****** SYSTEM REQUIREMENT 2 *****/
- pinMode(LED_PIN_D5, OUTPUT); // Set the LED pin as output
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- Power_PushButton_D2.read();
- Power_PushButton_D3.read();
- // Add your code to handle button events here
- /****** SYSTEM REQUIREMENT 1 *****/
- if (Power_PushButton_D2.wasPressed()) {
- isButtonD2Pressed = true;
- digitalWrite(LED_PIN_D4, HIGH); // Turn on the LED
- }
- if (Power_PushButton_D2.wasReleased()) {
- isButtonD2Pressed = false;
- digitalWrite(LED_PIN_D4, LOW); // Turn off the LED
- }
- /****** SYSTEM REQUIREMENT 2 *****/
- if (Power_PushButton_D3.wasPressed()) {
- isButtonD3Pressed = true;
- digitalWrite(LED_PIN_D5, HIGH); // Turn on the LED
- }
- if (Power_PushButton_D3.wasReleased()) {
- isButtonD3Pressed = false;
- digitalWrite(LED_PIN_D5, LOW); // Turn off the LED
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement