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:
- 5:5bf6cd9dffb7
- Parent:
- 4:ab83633679f4
- Child:
- 6:9a905505f955
--- a/main.cpp Tue Feb 11 10:19:43 2020 +0000
+++ b/main.cpp Wed Feb 12 04:54:34 2020 +0000
@@ -20,6 +20,36 @@
DigitalIn g_dpinIrReceiver(D2);
Serial g_serial(USBTX, USBRX);
DigitalOut myled(LED1);
+DigitalOut ir_out(D3);
+
+Timer timer;
+
+int IR_transmitte(char tx_data[64])
+{
+ //flame
+ //H
+ int t_start = timer.read_us();
+ ir_out = 1;
+ while( timer.read_us() - t_start < 625*16 );//16T
+ //L
+ t_start = timer.read_us();
+ ir_out = 0;
+ while( timer.read_us() - t_start < 625*8 );//8T
+
+ //data
+ for(int i=0; tx_data[i] != '\0'; i++ ) {
+ t_start = timer.read_us();
+ while( timer.read_us() - t_start < 625 ) ir_out = 1;
+ t_start = timer.read_us();
+ ir_out = 0;
+ if( tx_data[i] == '1') {
+ while( timer.read_us() - t_start < 625 );//1T
+ } else {
+ while( timer.read_us() - t_start < 625*3 );//3T
+ }
+ }
+ return 0;
+}
int main()
{
@@ -27,18 +57,20 @@
int t_negedge,t_posedge,t_delta,tx_delay;
int data_en = 0;
char rx_data[64] = "";
+ char tx_data[64] = "";
int busy = 0;
g_serial.baud(115200);
- Timer timer;
timer.start();
while(1) {
if(busy == 1) {
- for(int i=0;i<tx_delay;i++){
+ myled = 1;
+ for(int i=0; i<tx_delay; i++) {
wait_ms(1000);
}
//tx IR
+ IR_transmitte(tx_data);
myled = 0;
busy = 0;
} else {
@@ -60,9 +92,9 @@
g_serial.printf("received=");
if (strcmp(rx_data,OPT_PWR) == 0) {
g_serial.printf("PWR");
- myled = 1;
- tx_delay = 10;
+ tx_delay = 5;
//tx_data = CHANGHONG_23;
+ strcmp(tx_data,OPT_PWR);
} 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");