IRReceiver sample program of NucleoF042K6

Dependencies:   IRremote mbed

Files at this revision

API Documentation at this revision

Comitter:
Tiryoh
Date:
Tue Jan 09 11:39:37 2018 +0000
Commit message:
Initial commit

Changed in this revision

IRremote.lib 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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r a6e3441f2ddd IRremote.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IRremote.lib	Tue Jan 09 11:39:37 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/yuhki50/code/IRremote/#c82a0d54a024
diff -r 000000000000 -r a6e3441f2ddd main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Jan 09 11:39:37 2018 +0000
@@ -0,0 +1,78 @@
+#include "mbed.h"
+#include "IRremote.h"
+
+#define DURATION 0.2
+//#define PRINTF
+
+#ifdef PRINTF
+//Serial pc(USBTX, USBRX);
+Serial pc(PA_2, USBRX);
+#endif
+DigitalOut led_1(PB_7); //LED_1
+DigitalOut led_2(PB_6); //LED_2
+DigitalOut led_3(PB_5); //LED_3
+DigitalOut led_4(PB_4); //LED_4
+IRrecv irrecv(PA_7);
+decode_results results;
+
+#define PowerSwitch 0xA90
+//#define StopSwitch 0xA80
+#define Button5 0x210
+
+bool is_stop_received(void)
+{
+    if (irrecv.decode(&results))
+    {
+        if (results.decode_type == SONY && results.value == PowerSwitch)
+        {
+#ifdef PRINTF
+            pc.printf("stop\r\n");
+#endif
+            return true;
+        }
+        irrecv.resume();
+    }
+    return false;
+}
+
+bool is_start_received(void)
+{
+    if (irrecv.decode(&results))
+    {
+        if (results.decode_type == SONY && results.value == Button5)
+        {
+#ifdef PRINTF
+            pc.printf("start\r\n");
+#endif
+            return true;
+        }
+        irrecv.resume();
+    }
+    return false;
+}
+
+int main()
+{
+#ifdef PRINTF
+    pc.printf("init\r\n");
+#endif
+    irrecv.enableIRIn();
+    led_4 = 0;
+    while(!is_start_received())
+    {
+#ifdef PRINTF
+        pc.printf("waiting for start signal\r\n");
+        pc.printf("results.value : %x", results.value);
+#endif
+        wait(0.5);
+        led_4 = !led_4;
+    }
+    while(!is_stop_received())
+    {
+        led_4 = 0;
+        led_3 = 1;
+    }
+    
+    led_4 = 0;
+    led_3 = 0;
+}
\ No newline at end of file
diff -r 000000000000 -r a6e3441f2ddd mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Jan 09 11:39:37 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/b484a57bc302
\ No newline at end of file