NXP Rapid IoT prototiping kit ticker example.

Files at this revision

API Documentation at this revision

Comitter:
batman52
Date:
Thu Dec 26 16:53:44 2019 +0000
Parent:
79:0431b9fd3dc0
Commit message:
initial version from mbed documentation.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Nov 23 18:03:20 2019 +0000
+++ b/main.cpp	Thu Dec 26 16:53:44 2019 +0000
@@ -1,32 +1,27 @@
 #include "mbed.h"
 
+Ticker flipper;
+DigitalOut led1(LED_BLUE);
+DigitalOut led2(LED_RED);
+
+/*
 DigitalOut rgb_red(LED_RED, 1);       //     LED1 = LED_RED,  1 --> OFF, 0 --> ON
 DigitalOut rgb_blue(LED_BLUE, 1);     //     LED3 = LED_BLUE, 1 --> OFF, 0 --> ON
 DigitalOut rgb_green(PTE7,1);         //                      1 --> OFF, 0 --> ON
-
-void rgb_sel(int8_t idx) {
+*/
 
-switch(idx) {
-                case 0:
-                    rgb_red = 0; rgb_blue=1; rgb_green = 1;
-                    break;
-                case 1:
-                    rgb_red = 1; rgb_blue=0; rgb_green = 1;
-                    break;
-                case 2:
-                    rgb_red = 1; rgb_blue=1; rgb_green = 0;
-                    break;
-            }
-    
+void flip() {
+    led2 = !led2;
 }
 
-// main() runs in its own thread in the OS
 int main() {
-    int idx;
-    while (true) {
-        for(idx=0;idx<3;idx++) {
-            rgb_sel(idx);
-            wait(0.5);
-        }        
+    led2 = 1;
+    flipper.attach(&flip, 2.0); // call flip function every 2 seconds
+
+    // spin in a main loop. flipper will interrupt it to call flip
+    while(1) {
+        led1 = !led1;
+        //wait(0.5);
+        wait_us(500000);
     }
 }
\ No newline at end of file