![](/media/cache/profiles/Headshot_Fall2023_Square.jpg.50x50_q85.jpg)
New example. Initial version.
main.cpp
- Committer:
- CSTritt
- Date:
- 2021-10-01
- Revision:
- 109:b061f9830736
- Parent:
- 108:eee3167b25b4
- Child:
- 110:22b71c32c5e1
File content as of revision 109:b061f9830736:
/* Project: 21_Button-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. Modified 12 Aug 2017 by Dr. Sheila Ross Last revised 9/30/21 by Dr. C. S. Tritt */ #include "mbed.h" // Construct a digital input linked to the USER_BUTTON. DigitalIn myButton(USER_BUTTON); // Built in blue button. // Construct a digital output linked to LED1. DigitalOut myLed(LED1); // Built-in green LED. int main() { 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. } } }