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: Debounced Blink
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-09-21 07:02:56
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* ensure all functions are working properly */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void initSystem(void);
- bool isButtonPressed(void);
- void updateLED(void);
- // Pin definitions
- const int LED_PIN = 13;
- const int BUTTON_PIN = 2;
- // LED blink control
- unsigned long lastToggleTime = 0;
- unsigned int blinkInterval = 500; // milliseconds
- bool ledState = false;
- void initSystem(void)
- {
- // Initialize system components and state
- // (Currently handled in setup; this function reserved for future expansion)
- }
- void updateLED(void)
- {
- unsigned long now = millis();
- if (now - lastToggleTime >= blinkInterval) {
- lastToggleTime = now;
- ledState = !ledState;
- digitalWrite(LED_PIN, ledState ? HIGH : LOW);
- }
- }
- bool isButtonPressed(void)
- {
- // Simple debounce: detect a press and wait for release
- if (digitalRead(BUTTON_PIN) == LOW) {
- delay(50); // simple debounce
- if (digitalRead(BUTTON_PIN) == LOW) {
- // Wait for button release
- while (digitalRead(BUTTON_PIN) == LOW) {
- // busy wait
- }
- return true;
- }
- }
- return false;
- }
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(LED_PIN, OUTPUT);
- pinMode(BUTTON_PIN, INPUT_PULLUP);
- digitalWrite(LED_PIN, LOW);
- // Initialize last toggle time to current time
- lastToggleTime = millis();
- initSystem();
- }
- void loop(void)
- {
- // Debounced button press changes blink interval
- if (isButtonPressed()) {
- // Toggle between two speeds for visibility
- blinkInterval = (blinkInterval == 500) ? 200 : 500;
- }
- // Update LED state based on current interval
- updateLED();
- // Other tasks can be added here
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment