Demo using the user button and serial port on the Nucleo board, for Stage 1 Engineering at the University of York
main.cpp@3:e09e8c0d8dea, 2020-11-21 (annotated)
- Committer:
- ajp109
- Date:
- Sat Nov 21 13:44:40 2020 +0000
- Revision:
- 3:e09e8c0d8dea
- Parent:
- 2:bc854fc3d2a3
- Child:
- 4:20d75a9afbbd
Update to remove reliance on removed mbed Serial class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ajp109 | 0:fac2ffd6f143 | 1 | #include "mbed.h" |
ajp109 | 3:e09e8c0d8dea | 2 | #include "UoY-utils.h" |
ajp109 | 3:e09e8c0d8dea | 3 | |
ajp109 | 3:e09e8c0d8dea | 4 | // Initialise the serial connection with the PC |
ajp109 | 3:e09e8c0d8dea | 5 | serial_setup(USBTX, USBRX, 9600); |
ajp109 | 0:fac2ffd6f143 | 6 | |
ajp109 | 0:fac2ffd6f143 | 7 | int main() |
ajp109 | 0:fac2ffd6f143 | 8 | { |
ajp109 | 1:ee571cefc13b | 9 | // Initialise the digital pin USER_BUTTON (the blue button) as an input |
ajp109 | 1:ee571cefc13b | 10 | DigitalIn button(USER_BUTTON); |
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 | 2:bc854fc3d2a3 | 15 | if (button == true) { |
ajp109 | 3:e09e8c0d8dea | 16 | printf("Button is up\n"); |
ajp109 | 1:ee571cefc13b | 17 | } else { |
ajp109 | 3:e09e8c0d8dea | 18 | 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 | } |