Color sensor reset at the end of calibration added. sensor id auto assignment was changed to be a fixed value assignment to avoid sensor id shift when some sensor is absent.
Dependencies: UniGraphic mbed vt100
sensors/SMTC502AT.cpp@1:8818b793d147, 2018-02-23 (annotated)
- Committer:
- Rhyme
- Date:
- Fri Feb 23 07:51:55 2018 +0000
- Revision:
- 1:8818b793d147
- Parent:
- 0:ce97f6d34336
Wrong behavior when one of color sensor is missing has been fixed.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 0:ce97f6d34336 | 1 | #include "mbed.h" |
Rhyme | 0:ce97f6d34336 | 2 | #include "SMTC502AT.h" |
Rhyme | 0:ce97f6d34336 | 3 | |
Rhyme | 0:ce97f6d34336 | 4 | SMTC502AT::SMTC502AT(AnalogIn *ain, float R0, float R1, float B, float T0) |
Rhyme | 0:ce97f6d34336 | 5 | { |
Rhyme | 0:ce97f6d34336 | 6 | _ain = ain ; |
Rhyme | 0:ce97f6d34336 | 7 | _r0 = R0 ; |
Rhyme | 0:ce97f6d34336 | 8 | _r1 = R1 ; |
Rhyme | 0:ce97f6d34336 | 9 | _b = B ; |
Rhyme | 0:ce97f6d34336 | 10 | _t0 = T0 ; |
Rhyme | 0:ce97f6d34336 | 11 | } |
Rhyme | 0:ce97f6d34336 | 12 | |
Rhyme | 0:ce97f6d34336 | 13 | SMTC502AT::~SMTC502AT(void) |
Rhyme | 0:ce97f6d34336 | 14 | { |
Rhyme | 0:ce97f6d34336 | 15 | if (_ain) { |
Rhyme | 0:ce97f6d34336 | 16 | delete _ain ; |
Rhyme | 0:ce97f6d34336 | 17 | } |
Rhyme | 0:ce97f6d34336 | 18 | } |
Rhyme | 0:ce97f6d34336 | 19 | |
Rhyme | 0:ce97f6d34336 | 20 | /** |
Rhyme | 0:ce97f6d34336 | 21 | * getTemp returns the temperature |
Rhyme | 0:ce97f6d34336 | 22 | * operational temperature is -50C to +105C |
Rhyme | 0:ce97f6d34336 | 23 | */ |
Rhyme | 0:ce97f6d34336 | 24 | float SMTC502AT::getTemp(void) |
Rhyme | 0:ce97f6d34336 | 25 | { |
Rhyme | 0:ce97f6d34336 | 26 | float result = 0.0 ; |
Rhyme | 0:ce97f6d34336 | 27 | float f, raw, rr1, t ; |
Rhyme | 0:ce97f6d34336 | 28 | if (_ain) { |
Rhyme | 0:ce97f6d34336 | 29 | f = _ain->read() ; |
Rhyme | 0:ce97f6d34336 | 30 | #if 0 |
Rhyme | 0:ce97f6d34336 | 31 | if (f < 0.087) { /* +105C */ |
Rhyme | 0:ce97f6d34336 | 32 | printf("Temp is Too high or the sensor is absent\n") ; |
Rhyme | 0:ce97f6d34336 | 33 | f = 0.087 ; |
Rhyme | 0:ce97f6d34336 | 34 | } |
Rhyme | 0:ce97f6d34336 | 35 | if (f > 0.978) { /* -50C */ |
Rhyme | 0:ce97f6d34336 | 36 | printf("Temp is Too low or the sensor encountered a problem\n") ; |
Rhyme | 0:ce97f6d34336 | 37 | f = 0.978 ; |
Rhyme | 0:ce97f6d34336 | 38 | } |
Rhyme | 0:ce97f6d34336 | 39 | #endif |
Rhyme | 0:ce97f6d34336 | 40 | raw = f * 3.3 ; |
Rhyme | 0:ce97f6d34336 | 41 | rr1 = _r1 * raw / (3.3 - raw) ; |
Rhyme | 0:ce97f6d34336 | 42 | t = 1.0 / (log(rr1 / _r0) / _b + (1/_t0)) ; |
Rhyme | 0:ce97f6d34336 | 43 | result = t - 273.15 ; |
Rhyme | 0:ce97f6d34336 | 44 | } |
Rhyme | 0:ce97f6d34336 | 45 | return( result ) ; |
Rhyme | 0:ce97f6d34336 | 46 | } |
Rhyme | 0:ce97f6d34336 | 47 |