A demo program for STTS751 (I2C temperature sensor library)

Dependencies:   STTS751 mbed

Committer:
takuo
Date:
Wed Feb 05 04:28:22 2014 +0000
Revision:
3:a2d2563ae3ef
Parent:
2:9850512c9113
A usage example of standby mode is provided

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takuo 0:de38b1558115 1 /** A demo program for STTS751 (I2C temperature sensor library)
takuo 0:de38b1558115 2 * Takuo WATANABE (wtakuo)
takuo 0:de38b1558115 3 */
takuo 0:de38b1558115 4
takuo 0:de38b1558115 5 #include "mbed.h"
takuo 0:de38b1558115 6 #include "STTS751.h"
takuo 0:de38b1558115 7
takuo 0:de38b1558115 8 // I2C pins: p9 = sda, p10 = scl
takuo 3:a2d2563ae3ef 9 STTS751 sensor(p9, p10);
takuo 0:de38b1558115 10
takuo 0:de38b1558115 11 // You can specify an I2C object instead.
takuo 0:de38b1558115 12 // I2C i2c(p9, p10);
takuo 3:a2d2563ae3ef 13 // STTS751 sensor(i2c);
takuo 0:de38b1558115 14
takuo 3:a2d2563ae3ef 15 // example using continuous conversion mode
takuo 0:de38b1558115 16 int main() {
takuo 2:9850512c9113 17 // set the temperature resolution to 12bits
takuo 3:a2d2563ae3ef 18 sensor.setResolution(STTS751::RES_12);
takuo 3:a2d2563ae3ef 19 // set the conversion rate to 2/sec
takuo 3:a2d2563ae3ef 20 sensor.setConversionRate(5);
takuo 0:de38b1558115 21 while (true) {
takuo 3:a2d2563ae3ef 22 printf("temp: %.4f\n", (float)sensor);
takuo 0:de38b1558115 23 wait(1);
takuo 0:de38b1558115 24 }
takuo 0:de38b1558115 25 }
takuo 3:a2d2563ae3ef 26
takuo 3:a2d2563ae3ef 27 /*
takuo 3:a2d2563ae3ef 28 // example using standby mode
takuo 3:a2d2563ae3ef 29 int main() {
takuo 3:a2d2563ae3ef 30 // set the device to standby mode
takuo 3:a2d2563ae3ef 31 sensor.setStandbyMode(true);
takuo 3:a2d2563ae3ef 32 // set the temperature resolution to 12bits
takuo 3:a2d2563ae3ef 33 sensor.setResolution(STTS751::RES_12);
takuo 3:a2d2563ae3ef 34 while (true) {
takuo 3:a2d2563ae3ef 35 // start a temperature measurement
takuo 3:a2d2563ae3ef 36 sensor.start();
takuo 3:a2d2563ae3ef 37 // waiting for finishing the measurement
takuo 3:a2d2563ae3ef 38 while (!sensor.ready())
takuo 3:a2d2563ae3ef 39 wait(0.01);
takuo 3:a2d2563ae3ef 40 printf("temp: %.4f\n", sensor.temp(true));
takuo 3:a2d2563ae3ef 41 wait(1);
takuo 3:a2d2563ae3ef 42 }
takuo 3:a2d2563ae3ef 43 }
takuo 3:a2d2563ae3ef 44 */