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.
Fork of mbed-os-example-mbed5-blinky by
Diff: main.cpp
- Revision:
- 51:38bcf5ee4cb1
- Parent:
- 29:0b58d21e87d6
- Child:
- 52:fb9d943f4042
--- a/main.cpp Wed Nov 08 14:30:02 2017 +0000
+++ b/main.cpp Sat Nov 11 15:03:45 2017 +0000
@@ -2,11 +2,32 @@
DigitalOut led1(LED1);
+Serial pc(USBTX, USBRX);
+
+// blink a number in binary //
+void blink_in_binary (int number);
+
// main() runs in its own thread in the OS
int main() {
+// pc.baud(9600);
+ int number;
+ number = 0;
while (true) {
- led1 = !led1;
- wait(0.5);
+ while (!pc.readable());
+ pc.scanf("%d", &number);
+// pc.printf("you entered %d\n", number);
+ blink_in_binary(number);
}
}
+// recursivelly prints left-to-right //
+void blink_in_binary (int number)
+{
+ if (number <= 0)
+ return;
+ blink_in_binary (number >> 1);
+ led1 = number & 1;
+ wait(0.3);
+ led1 = 0;
+ wait(0.3);
+}
\ No newline at end of file
