Added a GPIO to power on/off for external I2C sensor(s) (with LEDs)

Dependencies:   UniGraphic mbed vt100

18-Jun-2018 外部センサの電源オン・オフ機能は下位互換の為に無効になっていました。 この版で再度有効にしました。

Committer:
Rhyme
Date:
Fri Apr 13 04:19:23 2018 +0000
Revision:
0:846e2321c637
power to color sensor on/off test OK. Currently the function is disabled.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:846e2321c637 1 #include "mbed.h"
Rhyme 0:846e2321c637 2 #include "SMTC502AT.h"
Rhyme 0:846e2321c637 3
Rhyme 0:846e2321c637 4 SMTC502AT::SMTC502AT(AnalogIn *ain, float R0, float R1, float B, float T0)
Rhyme 0:846e2321c637 5 {
Rhyme 0:846e2321c637 6 _ain = ain ;
Rhyme 0:846e2321c637 7 _r0 = R0 ;
Rhyme 0:846e2321c637 8 _r1 = R1 ;
Rhyme 0:846e2321c637 9 _b = B ;
Rhyme 0:846e2321c637 10 _t0 = T0 ;
Rhyme 0:846e2321c637 11 }
Rhyme 0:846e2321c637 12
Rhyme 0:846e2321c637 13 SMTC502AT::~SMTC502AT(void)
Rhyme 0:846e2321c637 14 {
Rhyme 0:846e2321c637 15 if (_ain) {
Rhyme 0:846e2321c637 16 delete _ain ;
Rhyme 0:846e2321c637 17 }
Rhyme 0:846e2321c637 18 }
Rhyme 0:846e2321c637 19
Rhyme 0:846e2321c637 20 /**
Rhyme 0:846e2321c637 21 * getTemp returns the temperature
Rhyme 0:846e2321c637 22 * operational temperature is -50C to +105C
Rhyme 0:846e2321c637 23 */
Rhyme 0:846e2321c637 24 float SMTC502AT::getTemp(void)
Rhyme 0:846e2321c637 25 {
Rhyme 0:846e2321c637 26 float result = 0.0 ;
Rhyme 0:846e2321c637 27 float f, raw, rr1, t ;
Rhyme 0:846e2321c637 28 if (_ain) {
Rhyme 0:846e2321c637 29 f = _ain->read() ;
Rhyme 0:846e2321c637 30 #if 0
Rhyme 0:846e2321c637 31 if (f < 0.087) { /* +105C */
Rhyme 0:846e2321c637 32 printf("Temp is Too high or the sensor is absent\n") ;
Rhyme 0:846e2321c637 33 f = 0.087 ;
Rhyme 0:846e2321c637 34 }
Rhyme 0:846e2321c637 35 if (f > 0.978) { /* -50C */
Rhyme 0:846e2321c637 36 printf("Temp is Too low or the sensor encountered a problem\n") ;
Rhyme 0:846e2321c637 37 f = 0.978 ;
Rhyme 0:846e2321c637 38 }
Rhyme 0:846e2321c637 39 #endif
Rhyme 0:846e2321c637 40 raw = f * 3.3 ;
Rhyme 0:846e2321c637 41 rr1 = _r1 * raw / (3.3 - raw) ;
Rhyme 0:846e2321c637 42 t = 1.0 / (log(rr1 / _r0) / _b + (1/_t0)) ;
Rhyme 0:846e2321c637 43 result = t - 273.15 ;
Rhyme 0:846e2321c637 44 }
Rhyme 0:846e2321c637 45 return( result ) ;
Rhyme 0:846e2321c637 46 }
Rhyme 0:846e2321c637 47