![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Demo using the user button and serial port on the Nucleo board, for Stage 1 Engineering at the University of York
Diff: main.cpp
- Revision:
- 1:ee571cefc13b
- Parent:
- 0:fac2ffd6f143
- Child:
- 2:bc854fc3d2a3
diff -r fac2ffd6f143 -r ee571cefc13b main.cpp --- a/main.cpp Tue Aug 25 11:00:34 2020 +0000 +++ b/main.cpp Thu Aug 27 10:14:27 2020 +0000 @@ -3,18 +3,21 @@ int main() { - // Initialise the digital pin LED1 as an output - DigitalOut led(LED1); + // Initialise the digital pin USER_BUTTON (the blue button) as an input + DigitalIn button(USER_BUTTON); + + // Initialise the serial connection with the PC + Serial pc(USBTX, USBRX); // Loop forever... while (true) { - // Switch the LED on - led = true; - // Wait for 200ms - thread_sleep_for(200); - // Switch the LED off - led = false; - // Wait for 300ms - thread_sleep_for(300); + // Is the button being pressed? + if (button) { + pc.printf("Button is up\n"); + } else { + pc.printf("Button is down\n"); + } + // Wait for 500ms + thread_sleep_for(500); } }