![](/media/cache/profiles/Headshot_Fall2023_Square.jpg.50x50_q85.jpg)
New example. Initial version.
Diff: main.cpp
- Revision:
- 109:b061f9830736
- Parent:
- 108:eee3167b25b4
- Child:
- 110:22b71c32c5e1
--- a/main.cpp Tue Sep 21 02:00:55 2021 +0000 +++ b/main.cpp Fri Oct 01 02:45:38 2021 +0000 @@ -1,31 +1,29 @@ /* - Project: BinaryCount - File: main.cpp - - Displays 8 bit binary count on bar graph display. - - Written by: Dr. C. S. Tritt - Created: 9/20/21 (v. 1.2) +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" -BusOut barGraph(D2, D3, D4, D5, D6, D7, D8, D9); // Create BusOut object. +// 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() { - // Test the wiring. - barGraph = 0; // All bars off (base 10). - ThisThread::sleep_for(400); // For 0.4 seconds. - barGraph = 0b01010101; // Odd bars on (binary). - ThisThread::sleep_for(400); // Test even bars for 0.4 seconds. - barGraph = 0b10101010; // Even bars on (binary). - ThisThread::sleep_for(400); // Test even bars for 0.4 seconds. - barGraph = 0xFF; // All bars on. Hex. - ThisThread::sleep_for(400); // For 0.4 seconds. - // Enter main loop. - while(true) { - for (int i = 0; i < 256; i++) { // Add one to count. - barGraph = i; // Copy the count to the bargraph. - ThisThread::sleep_for(100); // Display the value for 0.1 seconds. +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. } } } \ No newline at end of file