An application for school

Committer:
chris
Date:
Fri Oct 26 20:34:16 2012 +0000
Revision:
0:1be38995591b
Child:
1:6a70c9303bbe
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 0:1be38995591b 1
chris 0:1be38995591b 2 /*
chris 0:1be38995591b 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
chris 0:1be38995591b 4
chris 0:1be38995591b 5 Permission is hereby granted, free of charge, to any person obtaining a copy
chris 0:1be38995591b 6 of this software and associated documentation files (the "Software"), to deal
chris 0:1be38995591b 7 in the Software without restriction, including without limitation the rights
chris 0:1be38995591b 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
chris 0:1be38995591b 9 copies of the Software, and to permit persons to whom the Software is
chris 0:1be38995591b 10 furnished to do so, subject to the following conditions:
chris 0:1be38995591b 11
chris 0:1be38995591b 12 The above copyright notice and this permission notice shall be included in
chris 0:1be38995591b 13 all copies or substantial portions of the Software.
chris 0:1be38995591b 14
chris 0:1be38995591b 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
chris 0:1be38995591b 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
chris 0:1be38995591b 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
chris 0:1be38995591b 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
chris 0:1be38995591b 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
chris 0:1be38995591b 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
chris 0:1be38995591b 21 THE SOFTWARE.
chris 0:1be38995591b 22 */
chris 0:1be38995591b 23
chris 0:1be38995591b 24 #include "LM75B.h"
chris 0:1be38995591b 25
chris 0:1be38995591b 26 LM75B::LM75B(PinName sda, PinName scl) : i2c(sda, scl)
chris 0:1be38995591b 27 {
chris 0:1be38995591b 28 char cmd[2];
chris 0:1be38995591b 29 cmd[0] = LM75B_Conf;
chris 0:1be38995591b 30 cmd[1] = 0x0;
chris 0:1be38995591b 31 i2c.write( LM75B_ADDR, cmd, 2);
chris 0:1be38995591b 32 }
chris 0:1be38995591b 33
chris 0:1be38995591b 34
chris 0:1be38995591b 35
chris 0:1be38995591b 36 LM75B::~LM75B()
chris 0:1be38995591b 37 {
chris 0:1be38995591b 38
chris 0:1be38995591b 39 }
chris 0:1be38995591b 40
chris 0:1be38995591b 41 float LM75B::read()
chris 0:1be38995591b 42 {
chris 0:1be38995591b 43 char cmd[2];
chris 0:1be38995591b 44 cmd[0] = LM75B_Temp;
chris 0:1be38995591b 45
chris 0:1be38995591b 46 i2c.write( LM75B_ADDR, cmd, 1); // Send command string
chris 0:1be38995591b 47 i2c.read( LM75B_ADDR, cmd, 2); // Send command string
chris 0:1be38995591b 48 return ( float((cmd[0]<<8)|cmd[1]) / 256.0 );
chris 0:1be38995591b 49 }