A Simple Hello World for the DS1721 Digital Temperature Sensor.

Dependencies:   DS1721 mbed

Committer:
chaegle
Date:
Wed Apr 30 04:05:15 2014 +0000
Revision:
0:4ccb5fa61247
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chaegle 0:4ccb5fa61247 1
chaegle 0:4ccb5fa61247 2 #include "mbed.h"
chaegle 0:4ccb5fa61247 3 #include "DS1721.h"
chaegle 0:4ccb5fa61247 4
chaegle 0:4ccb5fa61247 5 #if defined(TARGET_KL25Z)
chaegle 0:4ccb5fa61247 6 #define I2C_SDA D7 // D7
chaegle 0:4ccb5fa61247 7 #define I2C_SCL D6 // D6
chaegle 0:4ccb5fa61247 8 //#define I2C_SDA D14 // D14
chaegle 0:4ccb5fa61247 9 //#define I2C_SCL D15 // D15
chaegle 0:4ccb5fa61247 10 #elif defined(TARGET_K64F)
chaegle 0:4ccb5fa61247 11 #define I2C_SDA PTE25 // D14
chaegle 0:4ccb5fa61247 12 #define I2C_SCL PTE24 // D15
chaegle 0:4ccb5fa61247 13 #endif
chaegle 0:4ccb5fa61247 14
chaegle 0:4ccb5fa61247 15 Serial pc(USBTX, USBRX);
chaegle 0:4ccb5fa61247 16
chaegle 0:4ccb5fa61247 17 int main(void)
chaegle 0:4ccb5fa61247 18 {
chaegle 0:4ccb5fa61247 19 float cTemp;
chaegle 0:4ccb5fa61247 20
chaegle 0:4ccb5fa61247 21 pc.baud(115200);
chaegle 0:4ccb5fa61247 22 pc.printf("DS1721 application started.\r\n");
chaegle 0:4ccb5fa61247 23
chaegle 0:4ccb5fa61247 24 I2C m_i2c(I2C_SDA, I2C_SCL);
chaegle 0:4ccb5fa61247 25
chaegle 0:4ccb5fa61247 26 DS1721 thermo(m_i2c, (DS1721_ADDR<<1));
chaegle 0:4ccb5fa61247 27
chaegle 0:4ccb5fa61247 28
chaegle 0:4ccb5fa61247 29
chaegle 0:4ccb5fa61247 30 // initialize the temperature sensor
chaegle 0:4ccb5fa61247 31 thermo.startConversion();
chaegle 0:4ccb5fa61247 32 thermo.setLowSp(25.00);
chaegle 0:4ccb5fa61247 33 thermo.setHighSp(27.25);
chaegle 0:4ccb5fa61247 34 thermo.setPolarity(POLARITY_ACTIVE_HIGH);
chaegle 0:4ccb5fa61247 35
chaegle 0:4ccb5fa61247 36 while (true)
chaegle 0:4ccb5fa61247 37 {
chaegle 0:4ccb5fa61247 38 cTemp = thermo.getTemp();
chaegle 0:4ccb5fa61247 39 pc.printf("Temp: %.2fC/%.2fF\r\n", cTemp, thermo.temp_CtoF(cTemp));
chaegle 0:4ccb5fa61247 40 wait(2.0);
chaegle 0:4ccb5fa61247 41 }
chaegle 0:4ccb5fa61247 42 }