han back
/
CLEO_UART_IR
SMART CLEO Uart IR
Diff: main.cpp
- Revision:
- 1:f8749f23bfda
- Parent:
- 0:867daeb1e2b2
--- a/main.cpp Thu Sep 28 03:34:43 2017 +0000 +++ b/main.cpp Thu Sep 28 04:48:31 2017 +0000 @@ -17,10 +17,12 @@ Serial SerialUART(PA_2, PA_3); uint8_t Buffer[37]; +uint8_t ir_flag = 1; //UART_buf RX_BUF; -InterruptIn IR_Detect(pin_IR_D); +//InterruptIn IR_Detect(pin_IR_D); +DigitalIn IR_Detect(pin_IR_D); //Ticker Sensor_Timer; @@ -38,11 +40,37 @@ //Timer_setting(0x06, 2); - IR_Detect.rise(&Sensor_Read_R); - IR_Detect.fall(&Sensor_Read_F); + //IR_Detect.rise(&Sensor_Read_R); + //IR_Detect.fall(&Sensor_Read_F); while(1) { + if(IR_Detect && ir_flag) + { + ir_flag = 0; + Buffer[0] = 0x76; + Buffer[1] = 0x01; + Buffer[2] = 0x03; + Buffer[3] = 0x01; + Buffer[4] = 1; + Buffer[5] = 0x3E; + for(int i=0; i<6; i++) + SerialUART.putc(Buffer[i]); + wait(1); + } + else if((IR_Detect == 0) && (ir_flag == 0)) + { + ir_flag = 1; + Buffer[0] = 0x76; + Buffer[1] = 0x01; + Buffer[2] = 0x03; + Buffer[3] = 0x01; + Buffer[4] = 0; + Buffer[5] = 0x3E; + for(int i=0; i<6; i++) + SerialUART.putc(Buffer[i]); + wait(1); + } } }