Initial version. Illuminates the LED when the user button is held down. Otherwise, the LED is off. Variation on 21_Button_v5.
Diff: main.cpp
- Revision:
- 110:6360f8487c16
- Parent:
- 109:b061f9830736
- Child:
- 111:2d91fe50a8cc
--- a/main.cpp Fri Oct 01 02:45:38 2021 +0000 +++ b/main.cpp Tue Oct 05 12:52:54 2021 +0000 @@ -1,13 +1,11 @@ /* -Project: 21_Button-v5 +Project: 21_ButtonImproved_v5 File: main.cpp -Toogles LED1 when USER_BUTTON is tapped. Note LED1 is also PA_5 which is -also D13. Based on built-in mbed example Nucleo_read_button. Holding the button -down will result in LED flashing. +Turns LED1 on when USER_BUTTON is held down. Otherwise LED1 is off. Modified 12 Aug 2017 by Dr. Sheila Ross -Last revised 9/30/21 by Dr. C. S. Tritt +Last revised 10/5/21 by Dr. C. S. Tritt */ #include "mbed.h" @@ -20,10 +18,12 @@ int main() { + myLed = 0; // Start with LED off (the default) while(true) { // Main loop. - if (myButton == 0) { // Button is active low. - myLed = !myLed; // Toggle LED on/off. - ThisThread::sleep_for(100); // Avoid double-tap, 0.1 seconds. + if (!myButton) { // Button is active low. + myLed = 1; // Turn LED on. + while (!myButton); // Wait here for button release. + myLed = 0; // Turn LED back off. } } } \ No newline at end of file