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.
Revision 3:f7beb1c93ba8, committed 2020-06-29
- Comitter:
- rary
- Date:
- Mon Jun 29 06:50:06 2020 +0000
- Parent:
- 2:8689bf235745
- Commit message:
- finish practice
Changed in this revision
BAROMETER.cpp | Show annotated file Show diff for this revision Revisions of this file |
BAROMETER.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/BAROMETER.cpp Mon Jun 29 05:13:36 2020 +0000 +++ b/BAROMETER.cpp Mon Jun 29 06:50:06 2020 +0000 @@ -1,11 +1,11 @@ #include "mbed.h" #include "BAROMETER.h" -BAROMETER::BAROMETER( PinName sda, PinName scl, adress ) : i2c(sda, scl), _addr(adress) +BAROMETER::BAROMETER( PinName sda, PinName scl, char adress ) : i2c(sda, scl), _addr(adress) { } -BAROMETR::~BAROMETER() +BAROMETER::~BAROMETER() { } @@ -13,14 +13,15 @@ { char cmd[2]; cmd[0]=regist; - i2c.write(addr,cmd,1); - i2c.read(addr,cmd,1); + i2c.write(_addr,cmd,1); + i2c.read(_addr,cmd,1); return cmd[0]; } void BAROMETER::i2c_write(char regist,char data) { + char cmd[2]; cmd[0]=regist; cmd[1]=data; - i2c.write(addr,cmd,2); + i2c.write(_addr,cmd,2); }
--- a/BAROMETER.h Mon Jun 29 05:13:36 2020 +0000 +++ b/BAROMETER.h Mon Jun 29 06:50:06 2020 +0000 @@ -1,4 +1,4 @@ -#ifdef MBED_BAROMETER_H +#ifndef MBED_BAROMETER_H #define MBED_BAROMETER_H #include "mbed.h" @@ -6,14 +6,14 @@ class BAROMETER { public: - BAROMETER(PinName sda, PinName scl, adress = 0xB8); + BAROMETER(PinName sda, PinName scl, char adress = 0xB8); ~BAROMETER(); char i2c_read(char regist); void i2c_write(char regist,char data); private: - I2c _i2c; + I2C i2c; char _addr; };