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:
Tue Oct 05 13:22:20 2021 +0000
Revision:
111:2d91fe50a8cc
Parent:
110:6360f8487c16
Cleaned up comments. Added version number starting at v. 1.0.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CSTritt 107:61b9c99a4e27 1 /*
CSTritt 111:2d91fe50a8cc 2 Project: 21_ButtonImproved_v5 (Button/LED Demo)
CSTritt 109:b061f9830736 3 File: main.cpp
CSTritt 109:b061f9830736 4
CSTritt 110:6360f8487c16 5 Turns LED1 on when USER_BUTTON is held down. Otherwise LED1 is off.
CSTritt 109:b061f9830736 6
CSTritt 109:b061f9830736 7 Modified 12 Aug 2017 by Dr. Sheila Ross
CSTritt 111:2d91fe50a8cc 8 Last revised 10/5/21 by Dr. C. S. Tritt (v. 1.0)
CSTritt 107:61b9c99a4e27 9 */
CSTritt 109:b061f9830736 10
Jonathan Austin 0:2757d7abb7d9 11 #include "mbed.h"
CSTritt 108:eee3167b25b4 12
CSTritt 109:b061f9830736 13 // Construct a digital input linked to the USER_BUTTON.
CSTritt 109:b061f9830736 14 DigitalIn myButton(USER_BUTTON); // Built in blue button.
CSTritt 109:b061f9830736 15
CSTritt 109:b061f9830736 16 // Construct a digital output linked to LED1.
CSTritt 109:b061f9830736 17 DigitalOut myLed(LED1); // Built-in green LED.
CSTritt 108:eee3167b25b4 18
CSTritt 109:b061f9830736 19 int main()
CSTritt 109:b061f9830736 20 {
CSTritt 110:6360f8487c16 21 myLed = 0; // Start with LED off (the default)
CSTritt 109:b061f9830736 22 while(true) { // Main loop.
CSTritt 110:6360f8487c16 23 if (!myButton) { // Button is active low.
CSTritt 110:6360f8487c16 24 myLed = 1; // Turn LED on.
CSTritt 110:6360f8487c16 25 while (!myButton); // Wait here for button release.
CSTritt 110:6360f8487c16 26 myLed = 0; // Turn LED back off.
CSTritt 108:eee3167b25b4 27 }
CSTritt 108:eee3167b25b4 28 }
CSTritt 108:eee3167b25b4 29 }