![](/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
main.cpp@1:ee571cefc13b, 2020-08-27 (annotated)
- Committer:
- ajp109
- Date:
- Thu Aug 27 10:14:27 2020 +0000
- Revision:
- 1:ee571cefc13b
- Parent:
- 0:fac2ffd6f143
- Child:
- 2:bc854fc3d2a3
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ajp109 | 0:fac2ffd6f143 | 1 | |
ajp109 | 0:fac2ffd6f143 | 2 | #include "mbed.h" |
ajp109 | 0:fac2ffd6f143 | 3 | |
ajp109 | 0:fac2ffd6f143 | 4 | int main() |
ajp109 | 0:fac2ffd6f143 | 5 | { |
ajp109 | 1:ee571cefc13b | 6 | // Initialise the digital pin USER_BUTTON (the blue button) as an input |
ajp109 | 1:ee571cefc13b | 7 | DigitalIn button(USER_BUTTON); |
ajp109 | 1:ee571cefc13b | 8 | |
ajp109 | 1:ee571cefc13b | 9 | // Initialise the serial connection with the PC |
ajp109 | 1:ee571cefc13b | 10 | Serial pc(USBTX, USBRX); |
ajp109 | 0:fac2ffd6f143 | 11 | |
ajp109 | 0:fac2ffd6f143 | 12 | // Loop forever... |
ajp109 | 0:fac2ffd6f143 | 13 | while (true) { |
ajp109 | 1:ee571cefc13b | 14 | // Is the button being pressed? |
ajp109 | 1:ee571cefc13b | 15 | if (button) { |
ajp109 | 1:ee571cefc13b | 16 | pc.printf("Button is up\n"); |
ajp109 | 1:ee571cefc13b | 17 | } else { |
ajp109 | 1:ee571cefc13b | 18 | pc.printf("Button is down\n"); |
ajp109 | 1:ee571cefc13b | 19 | } |
ajp109 | 1:ee571cefc13b | 20 | // Wait for 500ms |
ajp109 | 1:ee571cefc13b | 21 | thread_sleep_for(500); |
ajp109 | 0:fac2ffd6f143 | 22 | } |
ajp109 | 0:fac2ffd6f143 | 23 | } |