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.
main.cpp
00001 //********************** 00002 // Infrared Rays receiver and transceiver sample for mbed 00003 // 00004 // LPC1768 flash=512KB, ADC=12bits 00005 // LPC11U35 flash=64KB, ADC=10bits 00006 // Nucleo F401RE flash=512KB, ADC=12bits 00007 // 00008 // (C)Copyright 2014-2015 All rights reserved by Y.Onodera 00009 // http://einstlab.web.fc2.com 00010 //********************** 00011 #include "mbed.h" 00012 #include "AQM0802.h" 00013 #include "IR.h" 00014 00015 //#pragma O0 00016 //#pragma O1 00017 //#pragma O2 00018 //#pragma O3 // default 00019 //#pragma Otime // default 00020 //#pragma Ospace 00021 00022 00023 #if defined(TARGET_LPC1768) 00024 DigitalOut led1(LED1); 00025 DigitalOut led2(LED2); 00026 I2C i2c(p28,p27); 00027 AnalogIn ain(p15); 00028 #endif 00029 // for TG-LPC11U35-501 00030 #if defined (TARGET_LPC11U35_501) 00031 DigitalOut led1(P0_20); 00032 DigitalOut led2(P0_21); 00033 I2C i2c(P0_5,P0_4); 00034 AnalogIn ain(P0_11); 00035 #endif 00036 // for Nucleo 00037 #if defined (TARGET_NUCLEO_F401RE) 00038 DigitalOut led1(D13); 00039 I2C i2c(D14,D15); 00040 AnalogIn ain(PA_0); 00041 #endif 00042 00043 AQM0802 lcd(i2c); 00044 IR ir(P0_12,P0_7); 00045 InterruptIn button(P0_12); 00046 00047 void irInterrupt() 00048 { 00049 led1=!led1; 00050 button.disable_irq(); // !!! not work !!! 00051 ir.getIR(); 00052 button.enable_irq(); 00053 00054 // To do something, code here 00055 00056 } 00057 00058 00059 int main() { 00060 00061 char msg[10]; 00062 char i,n; 00063 char name[][5]={"none","NEC ","AEHA","SONY"}; 00064 00065 button.fall(&irInterrupt); 00066 button.mode(PullUp); 00067 00068 sprintf(msg, "%d", SystemCoreClock ); 00069 lcd.locate(0,0); 00070 lcd.print(msg); 00071 wait(1); 00072 00073 while(1) { 00074 00075 lcd.locate(0,0); 00076 sprintf(msg,"%s",name[ir.mode]); // 1:NEC, 2:AEHA, 3:SONY 00077 lcd.print(msg); 00078 sprintf(msg,"%4d",ir.bits); // bits 00079 lcd.print(msg); 00080 00081 // scroll 00082 n=(ir.bits+7)/8; // bits to n bytes 00083 for(i=0;i<n;i++){ 00084 lcd.locate(0,1); 00085 sprintf(msg,"buf%02d=%02X",i,ir.buf[i]); // data 00086 lcd.print(msg); 00087 wait(1); 00088 } 00089 00090 00091 // Echo back 00092 button.fall(NULL); // disable Interrupt 00093 // set parameter to send out 00094 // ir.mode is 1:NEC, 2:AEHA or 3:SONY 00095 // ir.bits is number to send out less than IR_LIMITS x8 00096 // ir.buf[] are bytes buffer 00097 ir.setIR(); 00098 button.fall(&irInterrupt); // enable Interrupt 00099 lcd.locate(0,1); 00100 sprintf(msg,"sent out"); 00101 lcd.print(msg); 00102 wait(1); 00103 00104 } 00105 00106 } 00107 00108
Generated on Tue Jul 12 2022 18:46:01 by
1.7.2