yasuyuki onodera
/
mbed_IR
IR receiver for TG-LPC11U35-501
main.cpp@2:31c91b18bba9, 2015-09-25 (annotated)
- Committer:
- yasuyuki
- Date:
- Fri Sep 25 17:13:57 2015 +0000
- Revision:
- 2:31c91b18bba9
- Parent:
- 0:8ae7470a57ef
- Child:
- 3:7ecc01d39b46
adding transceiver
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yasuyuki | 0:8ae7470a57ef | 1 | //********************** |
yasuyuki | 0:8ae7470a57ef | 2 | // Infrared Rays receiver sample for mbed |
yasuyuki | 0:8ae7470a57ef | 3 | // |
yasuyuki | 0:8ae7470a57ef | 4 | // LPC1768 flash=512KB, ADC=12bits |
yasuyuki | 0:8ae7470a57ef | 5 | // LPC11U35 flash=64KB, ADC=10bits |
yasuyuki | 0:8ae7470a57ef | 6 | // Nucleo F401RE flash=512KB, ADC=12bits |
yasuyuki | 0:8ae7470a57ef | 7 | // |
yasuyuki | 2:31c91b18bba9 | 8 | // (C)Copyright 2014-2015 All rights reserved by Y.Onodera |
yasuyuki | 0:8ae7470a57ef | 9 | // http://einstlab.web.fc2.com |
yasuyuki | 0:8ae7470a57ef | 10 | //********************** |
yasuyuki | 0:8ae7470a57ef | 11 | #include "mbed.h" |
yasuyuki | 0:8ae7470a57ef | 12 | #include "AQM0802.h" |
yasuyuki | 0:8ae7470a57ef | 13 | #include "IR.h" |
yasuyuki | 0:8ae7470a57ef | 14 | |
yasuyuki | 0:8ae7470a57ef | 15 | //#pragma O0 |
yasuyuki | 0:8ae7470a57ef | 16 | //#pragma O1 |
yasuyuki | 2:31c91b18bba9 | 17 | //#pragma O2 |
yasuyuki | 2:31c91b18bba9 | 18 | //#pragma O3 // default |
yasuyuki | 2:31c91b18bba9 | 19 | //#pragma Otime // default |
yasuyuki | 0:8ae7470a57ef | 20 | //#pragma Ospace |
yasuyuki | 0:8ae7470a57ef | 21 | |
yasuyuki | 0:8ae7470a57ef | 22 | |
yasuyuki | 0:8ae7470a57ef | 23 | #if defined(TARGET_LPC1768) |
yasuyuki | 0:8ae7470a57ef | 24 | DigitalOut led1(LED1); |
yasuyuki | 0:8ae7470a57ef | 25 | DigitalOut led2(LED2); |
yasuyuki | 0:8ae7470a57ef | 26 | I2C i2c(p28,p27); |
yasuyuki | 0:8ae7470a57ef | 27 | AnalogIn ain(p15); |
yasuyuki | 0:8ae7470a57ef | 28 | #endif |
yasuyuki | 0:8ae7470a57ef | 29 | // for TG-LPC11U35-501 |
yasuyuki | 0:8ae7470a57ef | 30 | #if defined (TARGET_LPC11U35_501) |
yasuyuki | 0:8ae7470a57ef | 31 | DigitalOut led1(P0_20); |
yasuyuki | 0:8ae7470a57ef | 32 | DigitalOut led2(P0_21); |
yasuyuki | 0:8ae7470a57ef | 33 | I2C i2c(P0_5,P0_4); |
yasuyuki | 0:8ae7470a57ef | 34 | AnalogIn ain(P0_11); |
yasuyuki | 0:8ae7470a57ef | 35 | #endif |
yasuyuki | 0:8ae7470a57ef | 36 | // for Nucleo |
yasuyuki | 0:8ae7470a57ef | 37 | #if defined (TARGET_NUCLEO_F401RE) |
yasuyuki | 0:8ae7470a57ef | 38 | DigitalOut led1(D13); |
yasuyuki | 0:8ae7470a57ef | 39 | I2C i2c(D14,D15); |
yasuyuki | 0:8ae7470a57ef | 40 | AnalogIn ain(PA_0); |
yasuyuki | 0:8ae7470a57ef | 41 | #endif |
yasuyuki | 0:8ae7470a57ef | 42 | |
yasuyuki | 0:8ae7470a57ef | 43 | AQM0802 lcd(i2c); |
yasuyuki | 2:31c91b18bba9 | 44 | IR ir(P0_12,P0_13); |
yasuyuki | 0:8ae7470a57ef | 45 | InterruptIn button(P0_12); |
yasuyuki | 0:8ae7470a57ef | 46 | |
yasuyuki | 2:31c91b18bba9 | 47 | void irInterrupt() |
yasuyuki | 0:8ae7470a57ef | 48 | { |
yasuyuki | 0:8ae7470a57ef | 49 | led1=!led1; |
yasuyuki | 2:31c91b18bba9 | 50 | button.disable_irq(); // !!! not work !!! |
yasuyuki | 2:31c91b18bba9 | 51 | ir.getIR(); |
yasuyuki | 0:8ae7470a57ef | 52 | button.enable_irq(); |
yasuyuki | 0:8ae7470a57ef | 53 | |
yasuyuki | 0:8ae7470a57ef | 54 | // To do something, code here |
yasuyuki | 0:8ae7470a57ef | 55 | |
yasuyuki | 0:8ae7470a57ef | 56 | } |
yasuyuki | 0:8ae7470a57ef | 57 | |
yasuyuki | 2:31c91b18bba9 | 58 | |
yasuyuki | 0:8ae7470a57ef | 59 | int main() { |
yasuyuki | 0:8ae7470a57ef | 60 | |
yasuyuki | 0:8ae7470a57ef | 61 | char msg[10]; |
yasuyuki | 0:8ae7470a57ef | 62 | char i; |
yasuyuki | 0:8ae7470a57ef | 63 | |
yasuyuki | 2:31c91b18bba9 | 64 | button.fall(&irInterrupt); |
yasuyuki | 0:8ae7470a57ef | 65 | button.mode(PullUp); |
yasuyuki | 0:8ae7470a57ef | 66 | |
yasuyuki | 0:8ae7470a57ef | 67 | sprintf(msg, "%d", SystemCoreClock ); |
yasuyuki | 0:8ae7470a57ef | 68 | lcd.locate(0,0); |
yasuyuki | 0:8ae7470a57ef | 69 | lcd.print(msg); |
yasuyuki | 0:8ae7470a57ef | 70 | wait(1); |
yasuyuki | 0:8ae7470a57ef | 71 | |
yasuyuki | 0:8ae7470a57ef | 72 | while(1) { |
yasuyuki | 0:8ae7470a57ef | 73 | |
yasuyuki | 0:8ae7470a57ef | 74 | lcd.locate(0,0); |
yasuyuki | 0:8ae7470a57ef | 75 | sprintf(msg,"%02X",ir.bits); // bits |
yasuyuki | 0:8ae7470a57ef | 76 | lcd.print(msg); |
yasuyuki | 2:31c91b18bba9 | 77 | sprintf(msg,"%02X",ir.mode); // 1:NEC, 2:AEHA, 3:SONY |
yasuyuki | 0:8ae7470a57ef | 78 | lcd.print(msg); |
yasuyuki | 0:8ae7470a57ef | 79 | |
yasuyuki | 0:8ae7470a57ef | 80 | for(i=0;i<2;i++){ |
yasuyuki | 2:31c91b18bba9 | 81 | // for(i=5;i<7;i++){ |
yasuyuki | 0:8ae7470a57ef | 82 | sprintf(msg,"%02X",ir.buf[i]); // data |
yasuyuki | 0:8ae7470a57ef | 83 | lcd.print(msg); |
yasuyuki | 0:8ae7470a57ef | 84 | } |
yasuyuki | 0:8ae7470a57ef | 85 | |
yasuyuki | 0:8ae7470a57ef | 86 | lcd.locate(0,1); |
yasuyuki | 0:8ae7470a57ef | 87 | for(i=2;i<6;i++){ |
yasuyuki | 2:31c91b18bba9 | 88 | // for(i=11;i<15;i++){ |
yasuyuki | 0:8ae7470a57ef | 89 | sprintf(msg,"%02X",ir.buf[i]); // data |
yasuyuki | 0:8ae7470a57ef | 90 | lcd.print(msg); |
yasuyuki | 0:8ae7470a57ef | 91 | } |
yasuyuki | 0:8ae7470a57ef | 92 | wait(1); |
yasuyuki | 2:31c91b18bba9 | 93 | |
yasuyuki | 2:31c91b18bba9 | 94 | |
yasuyuki | 2:31c91b18bba9 | 95 | // Echo back |
yasuyuki | 2:31c91b18bba9 | 96 | button.fall(NULL); // disable Interrupt |
yasuyuki | 2:31c91b18bba9 | 97 | // set parameter to send out |
yasuyuki | 2:31c91b18bba9 | 98 | // ir.mode is 1:NEC, 2:AEHA or 3:SONY |
yasuyuki | 2:31c91b18bba9 | 99 | // ir.bits is number to send out less than IR_LIMITS x8 |
yasuyuki | 2:31c91b18bba9 | 100 | // ir.buf[] are bytes buffer |
yasuyuki | 2:31c91b18bba9 | 101 | ir.setIR(); |
yasuyuki | 2:31c91b18bba9 | 102 | button.fall(&irInterrupt); // enable Interrupt |
yasuyuki | 2:31c91b18bba9 | 103 | wait(1); |
yasuyuki | 2:31c91b18bba9 | 104 | |
yasuyuki | 2:31c91b18bba9 | 105 | |
yasuyuki | 0:8ae7470a57ef | 106 | } |
yasuyuki | 0:8ae7470a57ef | 107 | |
yasuyuki | 0:8ae7470a57ef | 108 | } |
yasuyuki | 2:31c91b18bba9 | 109 | |
yasuyuki | 2:31c91b18bba9 | 110 |