Team pumpkin pie. Tokai Univ., MicroMouse

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers gp2y0e.hpp Source File

gp2y0e.hpp

00001 //2016/09/17
00002 
00003 #include <mbed.h>
00004 
00005 #ifndef GP2Y0E_I2C_INCLUDE
00006 #define GP2Y0E_I2C_INCLUDE
00007 
00008 //Config
00009 //!Enable to Address Write.
00010 #define GP2Y0E_I2C_ADDR_WRITE
00011 //Config_end
00012 
00013 class GP2Y_I2C {
00014 private:
00015   I2C _i2c;
00016   DigitalOut _vpp;
00017 
00018   char Distance_addr[2];
00019   char ShiftBit_addr;
00020   char dateaddr[2];
00021   char cmd[2];
00022   char CatchShiftBit;
00023 
00024   void Init(void)
00025   {
00026     _vpp = 0;
00027     Distance_addr[0] = 0x5E;
00028     Distance_addr[1] = 0x5F;
00029     ShiftBit_addr = 0x35;
00030     CatchShiftBit = 0;
00031   }
00032   void i2c_write(int addr,char regist,char data);
00033   char i2c_read(int addr,char regist);
00034 
00035 public:
00036 
00037  GP2Y_I2C(PinName sda, PinName scl, PinName Gvpp) : _i2c(sda, scl), _vpp(Gvpp){
00038    Init();
00039  }
00040 
00041  GP2Y_I2C(I2C& i2c, PinName Gvpp) : _i2c(i2c), _vpp(Gvpp){
00042    Init();
00043  }
00044 
00045   /* Search Distance */
00046   int Distance(int addr);
00047 
00048   /* Check Shift Bit (0x01 ... Maximum Display 128cm , 0x02 ... Maximum Display 64cm(Default)) */
00049   int ShiftBit_Check(int addr);
00050 
00051   /*Address Write*/
00052   #ifdef GP2Y0E_I2C_ADDR_WRITE
00053   void GP2Y_ADDR_Write_Sequence(char SelectAd);
00054   #endif
00055 };
00056 
00057 #endif