Hello code for "Switch Science mbed LPC824"

Dependencies:   mbed

Fork of SwitchSciencembedLPC824_test by Mako SHIMURA

Files at this revision

API Documentation at this revision

Comitter:
okano
Date:
Mon Nov 03 00:06:59 2014 +0000
Parent:
0:f947ed831c67
Child:
2:482581f76a1d
Commit message:
device access is made as a class

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
test_LM75B.lib Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Nov 03 00:03:55 2014 +0000
+++ b/main.cpp	Mon Nov 03 00:06:59 2014 +0000
@@ -1,48 +1,13 @@
 #include "mbed.h"
-
-//  LM75B I2C slave address
-#define     ADDRESS_LM75B   0x90
+#include "test_LM75B.h"
 
-//  LM75B registers
-#define     LM75B_Conf      0x01
-#define     LM75B_Temp      0x00
-#define     LM75B_Tos       0x03
-#define     LM75B_Thyst     0x02
-
-I2C     i2c( p28, p27 );
-
-void    init( void );
-float   read_temp( void );
-
+test_LM75B  temp( p28, p27 );
 
 int main()
 {
-    init();
-
     while(1) {
-        printf( "temp = %7.3f\r\n", read_temp() );
+        printf( "temp = %7.3f\r\n", temp.read() );
         wait( 1 );
     }
 }
 
-void init( void )
-{
-    char    command[ 2 ];
-
-    command[ 0 ]    = LM75B_Conf;
-    command[ 1 ]    = 0x00;
-
-    i2c.write( ADDRESS_LM75B, command, 2 );
-}
-
-float read_temp( void )
-{
-    char    command[ 2 ];
-
-    command[ 0 ]    = LM75B_Temp;
-
-    i2c.write( ADDRESS_LM75B, command, 1 );  // Send command string
-    i2c.read(  ADDRESS_LM75B, command, 2 );  // read two bytes data
-
-    return ( (float)( (command[ 0 ] << 8)| command[1] ) / 256.0 );
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test_LM75B.lib	Mon Nov 03 00:06:59 2014 +0000
@@ -0,0 +1,1 @@
+test_LM75B#6ecb302da815