Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 2:f63cdb6f8a44
- Parent:
- 1:ee571cefc13b
- Child:
- 3:35d45c4dd5d2
--- 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;
+ }
}
}