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 LED Control
- - Source Code NOT compiled for: Arduino Nano
- - Source Code created on: 2024-04-25 11:35:11
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Ensure LED diode turns on for 50ms after pressing */
- /* the EasyButton. It should turn off after 50ms, */
- /* even if the button is still pressed. Allow */
- /* reactivation only after a 2s delay. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <EasyButton.h> // https://github.com/evert-arias/EasyButton
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void onPressedForDuration();
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Przycisk_PushButton_PIN_D2 = 2;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t Zawor_LED_PIN_D3 = 3;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool Zawor_LED_PIN_D3_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float Zawor_LED_PIN_D3_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Instance of the button.
- EasyButton button(Przycisk_PushButton_PIN_D2);
- bool ledActive = false;
- unsigned long lastActivationTime = 0;
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(Przycisk_PushButton_PIN_D2, INPUT_PULLUP);
- pinMode(Zawor_LED_PIN_D3, OUTPUT);
- // Initialize the button.
- button.begin();
- // Add the callback function to be called when the button is pressed for at least the given time.
- button.onPressedFor(2000, onPressedForDuration);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- button.read(); // Continuously read the status of the button.
- updateOutputs(); // Refresh output data
- }
- void updateOutputs()
- {
- if (ledActive && millis() - lastActivationTime >= 50) {
- Zawor_LED_PIN_D3_rawData = 0;
- ledActive = false;
- lastActivationTime = millis();
- }
- digitalWrite(Zawor_LED_PIN_D3, Zawor_LED_PIN_D3_rawData);
- }
- void onPressedForDuration()
- {
- if (millis() - lastActivationTime >= 2000) {
- Zawor_LED_PIN_D3_rawData = 1;
- ledActive = true;
- lastActivationTime = millis();
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement