
Template project for University of York ELE00032C Lab 1
Revision 2:f63cdb6f8a44, committed 2020-09-29
- Comitter:
- ajp109
- Date:
- Tue Sep 29 09:55:47 2020 +0000
- Parent:
- 1:ee571cefc13b
- Child:
- 3:35d45c4dd5d2
- Commit message:
- Initial commit of actual project (forked from base)
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Aug 27 10:14:27 2020 +0000 +++ b/main.cpp Tue Sep 29 09:55:47 2020 +0000 @@ -1,23 +1,28 @@ - #include "mbed.h" int main() { - // Initialise the digital pin USER_BUTTON (the blue button) as an input - DigitalIn button(USER_BUTTON); + // Initialise the digital pins D2 and D3 as outputs + DigitalOut green(D2); + DigitalOut red(D3); + + // Initialise the digital pins D4 and D5 as inputs with pullup resistors + DigitalIn PB1(D4, PullUp); + DigitalIn PB2(D5, PullUp); - // Initialise the serial connection with the PC - Serial pc(USBTX, USBRX); - // Loop forever... while (true) { - // Is the button being pressed? - if (button) { - pc.printf("Button is up\n"); - } else { - pc.printf("Button is down\n"); - } - // Wait for 500ms - thread_sleep_for(500); + // Is PB1 being pressed? + if (PB1 == false) { + // Light the red LED, extinguish the green + red = true; + green = false; + } + // Is PB2 being pressed? + if (PB2 == false) { + // Extinguish the red LED, light the green + red = false; + green = true; + } } }