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

Dependencies:   UoY-serial

main.cpp

Committer:
ajp109
Date:
2020-09-28
Revision:
2:bc854fc3d2a3
Parent:
1:ee571cefc13b
Child:
3:e09e8c0d8dea

File content as of revision 2:bc854fc3d2a3:

#include "mbed.h"

int main()
{
    // 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) {
        // Is the button being pressed?
        if (button == true) {
            pc.printf("Button is up\n");
        } else {
            pc.printf("Button is down\n");
        }    
        // Wait for 500ms
        thread_sleep_for(500);
    }
}