Demo using the user button and serial port on the Nucleo board, for Stage 1 Engineering at the University of York

Dependencies:   UoY-serial

Committer:
ajp109
Date:
Mon Sep 28 16:03:05 2020 +0000
Revision:
2:bc854fc3d2a3
Parent:
1:ee571cefc13b
Child:
3:e09e8c0d8dea
Update syntax for consistency with script

Who changed what in which revision?

UserRevisionLine numberNew 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 1:ee571cefc13b 5 // Initialise the digital pin USER_BUTTON (the blue button) as an input
ajp109 1:ee571cefc13b 6 DigitalIn button(USER_BUTTON);
ajp109 1:ee571cefc13b 7
ajp109 1:ee571cefc13b 8 // Initialise the serial connection with the PC
ajp109 1:ee571cefc13b 9 Serial pc(USBTX, USBRX);
ajp109 0:fac2ffd6f143 10
ajp109 0:fac2ffd6f143 11 // Loop forever...
ajp109 0:fac2ffd6f143 12 while (true) {
ajp109 1:ee571cefc13b 13 // Is the button being pressed?
ajp109 2:bc854fc3d2a3 14 if (button == true) {
ajp109 1:ee571cefc13b 15 pc.printf("Button is up\n");
ajp109 1:ee571cefc13b 16 } else {
ajp109 1:ee571cefc13b 17 pc.printf("Button is down\n");
ajp109 1:ee571cefc13b 18 }
ajp109 1:ee571cefc13b 19 // Wait for 500ms
ajp109 1:ee571cefc13b 20 thread_sleep_for(500);
ajp109 0:fac2ffd6f143 21 }
ajp109 0:fac2ffd6f143 22 }