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.
Fork of sensors by
sensors.cpp
00001 #include "sensors.h" 00002 #include "mbed.h" 00003 00004 extern Serial usb2pc; 00005 extern DigitalOut myled; 00006 //============================================================ 00007 void sr501::triggered() //触发中断!! 00008 { 00009 usb2pc.printf("sr501 Triggered!\r\n"); 00010 status = true; 00011 } 00012 //-------- 00013 sr501::sr501(PinName pSignal) //启动热释电!!! 00014 : status(false), signal1(pSignal),signal2(pSignal) 00015 { 00016 signal1.rise(this, &sr501::triggered); 00017 usb2pc.printf("sr501 start!\r\n"); 00018 } 00019 //------- 00020 bool sr501::operator==(const bool &target) 00021 { 00022 if(status == target) 00023 { 00024 return true; 00025 } 00026 else 00027 { 00028 return false; 00029 } 00030 } 00031 //------- 00032 void sr501::reset() 00033 { 00034 status = false; 00035 } 00036 //------- 00037 int sr501::read() 00038 { 00039 return signal2.read(); 00040 } 00041 //========================================== 00042 BH1750::BH1750(PinName sda,PinName scl) //启动光强!!!!!(默认设置) 00043 :link(sda,scl) 00044 { 00045 status = true; 00046 char mode[1]={BH1750_CONTINUOUS_HIGH_RES_MODE}; 00047 usb2pc.printf("modify\r\n"); 00048 while(status) 00049 { 00050 status = link.write(BH1750_I2CADDR, mode, sizeof(mode), false); 00051 wait_ms(10); 00052 } 00053 usb2pc.printf("BH1750 start with default mode!\r\n"); 00054 } 00055 //-------- 00056 BH1750::BH1750(PinName sda,PinName scl,char mode[]) //启动光强!!!!!(自定义设置) 00057 :link(sda,scl) 00058 { 00059 status = true; 00060 while(status) 00061 { 00062 status = link.write(BH1750_I2CADDR, mode, sizeof(mode), false); 00063 wait_ms(10); 00064 } 00065 usb2pc.printf("BH1750 start with customize mode!\r\n"); 00066 } 00067 //-------- 00068 float BH1750::getlightdata() //读取光强(lux) 00069 { 00070 status = true; 00071 status = link.read(BH1750_I2CADDR, rawdata, 2, false); 00072 if(!status) 00073 { 00074 float result = ((rawdata[0]<<8)|rawdata[1])/1.2; 00075 return result; 00076 } 00077 else 00078 { 00079 usb2pc.printf("BH1750 read fail!\r\n"); 00080 return -1; 00081 } 00082 }
Generated on Wed Jul 13 2022 10:25:13 by
