Initial version. Illuminates the LED when the user button is held down. Otherwise, the LED is off. Variation on 21_Button_v5.

Committer:
CSTritt
Date:
Fri Oct 01 02:45:38 2021 +0000
Revision:
109:b061f9830736
Parent:
108:eee3167b25b4
Child:
110:6360f8487c16
Initial Mbed v. 5 version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CSTritt 107:61b9c99a4e27 1 /*
CSTritt 109:b061f9830736 2 Project: 21_Button-v5
CSTritt 109:b061f9830736 3 File: main.cpp
CSTritt 109:b061f9830736 4
CSTritt 109:b061f9830736 5 Toogles LED1 when USER_BUTTON is tapped. Note LED1 is also PA_5 which is
CSTritt 109:b061f9830736 6 also D13. Based on built-in mbed example Nucleo_read_button. Holding the button
CSTritt 109:b061f9830736 7 down will result in LED flashing.
CSTritt 109:b061f9830736 8
CSTritt 109:b061f9830736 9 Modified 12 Aug 2017 by Dr. Sheila Ross
CSTritt 109:b061f9830736 10 Last revised 9/30/21 by Dr. C. S. Tritt
CSTritt 107:61b9c99a4e27 11 */
CSTritt 109:b061f9830736 12
Jonathan Austin 0:2757d7abb7d9 13 #include "mbed.h"
CSTritt 108:eee3167b25b4 14
CSTritt 109:b061f9830736 15 // Construct a digital input linked to the USER_BUTTON.
CSTritt 109:b061f9830736 16 DigitalIn myButton(USER_BUTTON); // Built in blue button.
CSTritt 109:b061f9830736 17
CSTritt 109:b061f9830736 18 // Construct a digital output linked to LED1.
CSTritt 109:b061f9830736 19 DigitalOut myLed(LED1); // Built-in green LED.
CSTritt 108:eee3167b25b4 20
CSTritt 109:b061f9830736 21 int main()
CSTritt 109:b061f9830736 22 {
CSTritt 109:b061f9830736 23 while(true) { // Main loop.
CSTritt 109:b061f9830736 24 if (myButton == 0) { // Button is active low.
CSTritt 109:b061f9830736 25 myLed = !myLed; // Toggle LED on/off.
CSTritt 109:b061f9830736 26 ThisThread::sleep_for(100); // Avoid double-tap, 0.1 seconds.
CSTritt 108:eee3167b25b4 27 }
CSTritt 108:eee3167b25b4 28 }
CSTritt 108:eee3167b25b4 29 }