trainning_template

Dependencies:   mbed

Revision:
4:fe1e9f9c7b33
Parent:
3:31aec950f7dc
--- a/sensors.h	Fri Sep 14 10:52:15 2018 +0000
+++ b/sensors.h	Thu Oct 18 16:23:13 2018 +0000
@@ -3,6 +3,27 @@
 
 #include "mbed.h"
 
+
+
+//==========================================
+class sr501
+{
+/*****
+ * 红外热释电对象
+ * 感应输出高电平
+*****/
+  private:
+//    DigitalIn signal;
+    bool status;
+    InterruptIn signal;
+    void triggered();
+  public:
+    sr501(PinName pSignal);
+    bool operator==(const bool &target);
+    void reset();
+    int read();
+};
+//=========================================
 //+++++++++++++++++++++BH1750+++++++++++++++++++++++++++++
 #define BH1750_I2CADDR 0x46
 #define BH1750_POWER_DOWN 0x00                  // No active state
@@ -23,27 +44,7 @@
 // Start measurement at 1lx resolution. Measurement time is approx 120ms.
 // Device is automatically set to Power Down after measurement.
 #define BH1750_ONE_TIME_LOW_RES_MODE  0x23
-//++++++++++++++++++++++++++++++++++++++++
-
-//==========================================
-class sr501
-{
-/*****
- * 红外热释电对象
- * 感应输出高电平
-*****/
-  private:
-//    DigitalIn signal;
-    bool status;
-    InterruptIn signal;
-    void triggered();
-  public:
-    sr501(PinName pSignal);
-    bool operator==(const bool &target);
-    void reset();
-    int read();
-};
-//=========================================
+//++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 class BH1750
 {
     
@@ -99,5 +100,120 @@
     float gettemperature();
 
 };
-//=======================
+//==========================================DS18B20
+class DS18B20
+{
+/*****
+*
+*****/
+  private:
+    DigitalInOut datapin;
+    uint8_t dat;
+    float T;
+
+    int start();
+    void writebyte(uint8_t send);
+    uint8_t readByte();
+    float transfer(uint8_t h,uint8_t l);                                 
+  public:
+    DS18B20(PinName pin);
+    int getdata();  
+    float gettemperature();
+
+};
+//==========================================YL-38通用传感
+class YL
+{
+/*****
+*
+*****/
+  private:
+    bool status;
+    InterruptIn signal;
+    AnalogIn signallevel;
+    
+    void triggered();                                     
+  public:
+    YL(PinName dio);
+    YL(PinName dio,PinName aio);
+    bool operator==(const bool &target);
+    float getairdata(); 
+    void reset();
+    int read();
+};
+//========================================
+#define BMP180_ADDRESS          0x77<<1 // I2C address of BMP180, eight bit address on mbed
+#define BMP180_WHO_AM_I         0xD0    // WHO_AM_I id of BMP180, should return 0x55
+#define BMP180_RESET            0xE0
+#define BMP180_CONTROL          0xF4
+#define BMP180_OUT_MSB          0xF6
+#define BMP180_OUT_LSB          0xF7
+#define BMP180_OUT_XLSB         0xF8
+
+// Set initial input parameters
+
+enum OSS {  // BMP-085 sampling rate
+  OSS_0 = 0,  // 4.5 ms conversion time
+  OSS_1=1,      // 7.5
+  OSS_2=2,      // 13.5
+  OSS_3=3       // 25.5
+};
+
+
+
+class BMP180 {
+/*****
+*
+*****/
+private:
+    uint8_t OSS;           // maximum pressure resolution
+
+    //Set up I2C, (SDA,SCL)
+    I2C i2c;
+    
+    // These are constants used to calculate the temperature and pressure from the BMP-180 sensor
+    int16_t ac1, ac2, ac3, b1, b2, mb, mc, md, b5;  
+    uint16_t ac4, ac5, ac6;   
+
+    void writeByte(uint8_t address, uint8_t subAddress, uint8_t data);
+    char readByte(uint8_t address, uint8_t subAddress);
+    void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t * dest);
+    
+    // Stores all of the BMP180's calibration values into global variables
+    // Calibration values are required to calculate temp and pressure
+    // This function should be called at the beginning of the program
+    // These BMP-180 functions were adapted from Jim Lindblom of SparkFun Electronics
+    void BMP180Calibration();
+public:
+    BMP180(PinName sda,PinName scl) ;
+    // Temperature returned will be in units of 0.1 deg C
+    long BMP180GetTemperature();
+
+    // Calculate pressure read calibration values  
+    // b5 is also required so BMP180GetTemperature() must be called first.
+    // Value returned will be pressure in units of Pa.
+    long BMP180GetPressure();
+};
+//================================================
+class GP2Y1010
+{
+/*****
+*
+*****/
+  private:
+    AnalogIn measurePin ;            
+    DigitalOut ledPower; 
+    unsigned int samplingTime ;
+    unsigned int deltaTime ;
+    unsigned int sleepTime ;
+ 
+    float voMeasured ;
+    float calcVoltage ;
+    float dustDensity ;
+                                      
+  public:
+    GP2Y1010(PinName ledPower,PinName measurePin);
+    float getairdata(); 
+};
+//=============================================
 #endif