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:
- 4:ab83633679f4
- Parent:
- 3:31c005437fa5
- Child:
- 5:5bf6cd9dffb7
--- a/main.cpp Tue Feb 11 08:26:57 2020 +0000
+++ b/main.cpp Tue Feb 11 10:19:43 2020 +0000
@@ -1,9 +1,12 @@
//reference from
//https://www.hiramine.com/physicalcomputing/mbed/irreceiver.html
-
+//http://elm-chan.org/docs/ir_format.html
#include "mbed.h"
+//compatible
+//http://akizukidenshi.com/catalog/g/gM-07245/
+//maybe 0000100011110111 is customer code
#define OPT_PWR "000010001111011100011011111001001"
#define OPT_A "000010001111011100011111111000001"
#define OPT_B "000010001111011100011110111000011"
@@ -14,66 +17,74 @@
#define OPT_LEFT "000010001111011100001000111101111"
#define OPT_RIGHT "000010001111011100000001111111101"
-
DigitalIn g_dpinIrReceiver(D2);
Serial g_serial(USBTX, USBRX);
+DigitalOut myled(LED1);
int main()
{
+ int iState_prev = 1;
+ int t_negedge,t_posedge,t_delta,tx_delay;
+ int data_en = 0;
+ char rx_data[64] = "";
+ int busy = 0;
+
g_serial.baud(115200);
-
Timer timer;
timer.start();
- int iState_prev = 1;
- int t_negedge,t_posedge,t_delta;
- int data_en = 0;
- char rx_data[64] = "";
-
while(1) {
- int iState = g_dpinIrReceiver;
+ if(busy == 1) {
+ for(int i=0;i<tx_delay;i++){
+ wait_ms(1000);
+ }
+ //tx IR
+ myled = 0;
+ busy = 0;
+ } else {
+ int iState = g_dpinIrReceiver;
+ //detect H signal
+ if( iState != iState_prev ) {
+ if(iState == 0) {
+ //timer.start();//reset
+ t_negedge = timer.read_us();//start(detect negedge
- //detect H signal
- if( iState != iState_prev ) {
- if(iState == 0) {
- //timer.start();//reset
- t_negedge = timer.read_us();//start(detect negedge
-
- if(data_en == 1) {
- t_delta = t_negedge - t_posedge;
- data_en = 0;
- if(t_delta > 1523) strcat(rx_data, "1");//g_serial.printf("1");//625*2.5
- else strcat(rx_data, "0");//g_serial.printf("0");
+ if(data_en == 1) {
+ t_delta = t_negedge - t_posedge;
+ data_en = 0;
+ if(t_delta > 1523) strcat(rx_data, "1");//625*2.5
+ else strcat(rx_data, "0");
- if(strlen(rx_data) == 33){
- //g_serial.printf("data=%s\r\n",rx_data);
- if (strcmp(rx_data,OPT_PWR) == 0) g_serial.printf("received=PWR\r\n",rx_data);
- else if (strcmp(rx_data,OPT_CENTRE) == 0) g_serial.printf("received=CENTRE\r\n",rx_data);
+ if(strlen(rx_data) == 33) {
+ busy = 1;
+ g_serial.printf("received=");
+ if (strcmp(rx_data,OPT_PWR) == 0) {
+ g_serial.printf("PWR");
+ myled = 1;
+ tx_delay = 10;
+ //tx_data = CHANGHONG_23;
+ } else if (strcmp(rx_data,OPT_A) == 0) g_serial.printf("A");
+ else if (strcmp(rx_data,OPT_B) == 0) g_serial.printf("B");
+ else if (strcmp(rx_data,OPT_C) == 0) g_serial.printf("C");
+ else if (strcmp(rx_data,OPT_CENTRE) == 0) g_serial.printf("CENTRE");
+ else if (strcmp(rx_data,OPT_TOP) == 0) g_serial.printf("TOP");
+ else if (strcmp(rx_data,OPT_UNDER) == 0) g_serial.printf("UNDER");
+ else if (strcmp(rx_data,OPT_LEFT) == 0) g_serial.printf("LEFT");
+ else if (strcmp(rx_data,OPT_RIGHT) == 0) g_serial.printf("RIGHT");
+ g_serial.printf("\r\n");
+ }
}
-
- }
- } else if(iState == 1) { //end (detect posedge
-
+ } else if(iState == 1) { //end (detect posedge
+ t_posedge = timer.read_us();
+ //compare and output
+ t_delta = t_posedge - t_negedge;
- t_posedge = timer.read_us();//over flow?
- //compare and output
- t_delta = t_posedge - t_negedge;
-
- if(t_delta > 8430) {
- //g_serial.printf("flame,");//625*15
- rx_data[0] = '\0';
- } else {
- data_en = 1;
- //g_serial.printf("data,");
- //g_serial.printf( "%d, ", t_negedge - t_posedge);
+ if(t_delta > 8430) {//625*15, flame
+ rx_data[0] = '\0';
+ } else data_en = 1;
}
}
+ iState_prev = iState;
}
- iState_prev = iState;
-
- //iState_prev = iState;
- //int iMicroSec = timer.read_us();
- //g_serial.printf( "%d, ", iMicroSec - iMicroSec_prev );
- //iMicroSec_prev = iMicroSec;
}
}
\ No newline at end of file