![](/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@5:4914c66f9a74, 2021-09-16 (annotated)
- Committer:
- ajp109
- Date:
- Thu Sep 16 14:01:20 2021 +0000
- Revision:
- 5:4914c66f9a74
- Parent:
- 4:20d75a9afbbd
Update pin name
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ajp109 | 0:fac2ffd6f143 | 1 | #include "mbed.h" |
ajp109 | 0:fac2ffd6f143 | 2 | |
ajp109 | 0:fac2ffd6f143 | 3 | int main() |
ajp109 | 0:fac2ffd6f143 | 4 | { |
ajp109 | 5:4914c66f9a74 | 5 | // Initialise the digital pin BUTTON1 (the blue button) as an input |
ajp109 | 5:4914c66f9a74 | 6 | DigitalIn button(BUTTON1); |
ajp109 | 0:fac2ffd6f143 | 7 | |
ajp109 | 0:fac2ffd6f143 | 8 | // Loop forever... |
ajp109 | 0:fac2ffd6f143 | 9 | while (true) { |
ajp109 | 1:ee571cefc13b | 10 | // Is the button being pressed? |
ajp109 | 2:bc854fc3d2a3 | 11 | if (button == true) { |
ajp109 | 3:e09e8c0d8dea | 12 | printf("Button is up\n"); |
ajp109 | 1:ee571cefc13b | 13 | } else { |
ajp109 | 3:e09e8c0d8dea | 14 | printf("Button is down\n"); |
ajp109 | 1:ee571cefc13b | 15 | } |
ajp109 | 1:ee571cefc13b | 16 | // Wait for 500ms |
ajp109 | 1:ee571cefc13b | 17 | thread_sleep_for(500); |
ajp109 | 0:fac2ffd6f143 | 18 | } |
ajp109 | 0:fac2ffd6f143 | 19 | } |