使用红外接收库的一个demo code

Dependencies:   mbed

Fork of IR_remote by Armando Casalino

Committer:
havebug
Date:
Thu Jul 13 11:37:43 2017 +0000
Revision:
2:35f80e65a141
Parent:
1:5e7be7addf96
Child:
3:29915623fbb0
stable 3 buttons 10 values pwm

Who changed what in which revision?

UserRevisionLine numberNew contents of line
havebug 0:42764550a2cb 1 #include "mbed.h"
havebug 0:42764550a2cb 2 #include "ReceiverIR.h"
havebug 2:35f80e65a141 3
havebug 2:35f80e65a141 4 DigitalOut my_led(LED1);
havebug 2:35f80e65a141 5
havebug 2:35f80e65a141 6 PwmOut my_pwm1(PB_3);
havebug 2:35f80e65a141 7 PwmOut my_pwm2(PB_5);
havebug 2:35f80e65a141 8
havebug 2:35f80e65a141 9
havebug 0:42764550a2cb 10 ReceiverIR ir_rx(D2);
havebug 0:42764550a2cb 11
havebug 0:42764550a2cb 12 Serial pc(SERIAL_TX, SERIAL_RX);
havebug 0:42764550a2cb 13 DigitalOut myled(LED1);
havebug 0:42764550a2cb 14
havebug 0:42764550a2cb 15 RemoteIR::Format format;
havebug 0:42764550a2cb 16 uint8_t buf[32];
havebug 0:42764550a2cb 17 int bitcount;
havebug 2:35f80e65a141 18 float DC=0.5;
havebug 0:42764550a2cb 19
havebug 0:42764550a2cb 20 int main()
havebug 0:42764550a2cb 21 {
havebug 2:35f80e65a141 22 my_pwm1.period_ms(10);
havebug 2:35f80e65a141 23 my_pwm1.write(DC);
havebug 2:35f80e65a141 24
havebug 2:35f80e65a141 25 my_pwm2.period_ms(10);
havebug 2:35f80e65a141 26 my_pwm2.write(DC);
havebug 2:35f80e65a141 27
havebug 2:35f80e65a141 28
havebug 0:42764550a2cb 29
havebug 0:42764550a2cb 30 pc.printf("Hello World !\r\n");
havebug 0:42764550a2cb 31 while(1) {
havebug 0:42764550a2cb 32
havebug 0:42764550a2cb 33 if (ir_rx.getState() == ReceiverIR::Received) {
havebug 0:42764550a2cb 34 bitcount = ir_rx.getData(&format, buf, sizeof(buf) * 8);
havebug 0:42764550a2cb 35
havebug 0:42764550a2cb 36 if (bitcount>0){
havebug 0:42764550a2cb 37
havebug 0:42764550a2cb 38 pc.printf("Decoded: %02X \r\n", buf[3]);
havebug 0:42764550a2cb 39 myled = !myled;
havebug 2:35f80e65a141 40
havebug 2:35f80e65a141 41 if (buf[3]==0xE5){
havebug 2:35f80e65a141 42 DC = DC+ 0.1;
havebug 2:35f80e65a141 43 if (DC>1) DC=1;
havebug 2:35f80e65a141 44 }
havebug 2:35f80e65a141 45 if (buf[3]==0xD4){
havebug 2:35f80e65a141 46 DC = DC- 0.1;
havebug 2:35f80e65a141 47 if (DC<0) DC=0;
havebug 2:35f80e65a141 48 }
havebug 2:35f80e65a141 49 if (buf[3]==0xC3){
havebug 2:35f80e65a141 50 DC = 0.5;
havebug 2:35f80e65a141 51 }
havebug 2:35f80e65a141 52
havebug 2:35f80e65a141 53 my_pwm1.write(DC);
havebug 2:35f80e65a141 54 my_pwm2.write(DC);
havebug 2:35f80e65a141 55
havebug 0:42764550a2cb 56
havebug 0:42764550a2cb 57 /* DEBUG
havebug 0:42764550a2cb 58 for (int i = 0; i < bitcount; i++) {
havebug 0:42764550a2cb 59 pc.printf("%02X", buf[i]);
havebug 0:42764550a2cb 60 }
havebug 0:42764550a2cb 61 */
havebug 0:42764550a2cb 62
havebug 0:42764550a2cb 63 }
havebug 0:42764550a2cb 64
havebug 0:42764550a2cb 65 }
havebug 0:42764550a2cb 66
havebug 0:42764550a2cb 67 }
havebug 0:42764550a2cb 68 }