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
Revision 19:ff7ac8de56f9, committed 2018-01-06
- Comitter:
- Pieter56
- Date:
- Sat Jan 06 11:27:36 2018 +0000
- Parent:
- 18:d15cf1cad4c9
- Commit message:
- Test versie
Changed in this revision
| img/uvision.png | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Nov 16 21:09:41 2016 +0000
+++ b/main.cpp Sat Jan 06 11:27:36 2018 +0000
@@ -1,22 +1,76 @@
#include "mbed.h"
+#include "Thread.h"
+
+// For FRDM board K64F
+#if defined TARGET_K64F
+#define button_pressed 0
+#define led_on 0
+#define led_off 1
+#define USERBUTTON SW2
+#define RED_LED LED1
+#define BLUE_LED LED2
+#define GREEN_LED LED3
+#endif
-DigitalOut led1(LED1, 0);
-DigitalOut led2(LED2, 0);
-DigitalOut led3(LED3, 0);
+// For NUCLEO-F429ZI
+#if defined TARGET_STM32F429ZI
+#define button_pressed 1
+#define led_on 1
+#define led_off 0
+#define USERBUTTON USER_BUTTON
+#define RED_LED LED3
+#define BLUE_LED LED2
+#define GREEN_LED LED1
+#endif
+
+DigitalOut red_led(RED_LED, led_off); // RED
+DigitalOut green_led(GREEN_LED, led_off); // GREEN
+DigitalOut blue_led(BLUE_LED, led_off); // BLUE
+DigitalIn button(USERBUTTON);
+
// main() runs in its own thread in the OS
// (note the calls to Thread::wait below for delays)
-int main() {
+// Connect to serial USB
+Serial pc(USBTX, USBRX, 115200);
+
+void led_thread() {
uint16_t color = 0;
while (true) {
- Thread::wait(1000);
- //led1 = !led1;
- //led2 = !led2;
color++;
color = color & 0x7;
- led1 = color & 0x1;
- led2 = (color >> 1) & 0x1;
- led3 = (color >> 2) & 0x1;
+ red_led = color & 0x1;
+ green_led = color & 0x2;
+ pc.printf("Color is: %d\r\n", color);
+ Thread::wait(1000);
}
}
+
+int main() {
+ //Create a thread to execute the function led_thread
+ Thread::Thread thread1;
+ thread1.start(&led_thread);
+ uint8_t b_reg = 0;
+
+ // Main thread
+ while (true) {
+ if (button_pressed == button) {
+ b_reg = b_reg << 1;
+ b_reg |= 1;
+ if ((b_reg & 0x17) == 0x17) {
+ blue_led = led_on;
+ pc.putc('*');
+ } else {
+ pc.putc('-');
+ }
+ }
+ else {
+ b_reg = 0;
+ blue_led = led_off;
+ }
+ Thread::wait(100);
+
+ }
+}
+
