LAME

Dependencies:   mbed 4DGL-uLCD-SE SDFileSystem PinDetect

Committer:
kmillion3
Date:
Sun May 01 22:17:57 2022 +0000
Revision:
5:05f7a84d0078
Parent:
2:58d85409f7ff
LAME;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 2:58d85409f7ff 1 #include "mbed.h"
4180_1 2:58d85409f7ff 2
4180_1 2:58d85409f7ff 3 //Setup a new class for TMP36 sensor
4180_1 2:58d85409f7ff 4 class TMP36
4180_1 2:58d85409f7ff 5 {
4180_1 2:58d85409f7ff 6 public:
4180_1 2:58d85409f7ff 7 TMP36(PinName pin);
4180_1 2:58d85409f7ff 8 TMP36();
4180_1 2:58d85409f7ff 9 operator float ();
4180_1 2:58d85409f7ff 10 float read();
4180_1 2:58d85409f7ff 11 private:
4180_1 2:58d85409f7ff 12 //class sets up the AnalogIn pin
4180_1 2:58d85409f7ff 13 AnalogIn _pin;
4180_1 2:58d85409f7ff 14 };
4180_1 2:58d85409f7ff 15
4180_1 2:58d85409f7ff 16 TMP36::TMP36(PinName pin) : _pin(pin)
4180_1 2:58d85409f7ff 17 {
4180_1 2:58d85409f7ff 18 // _pin(pin) means pass pin to the AnalogIn constructor
4180_1 2:58d85409f7ff 19 }
4180_1 2:58d85409f7ff 20
4180_1 2:58d85409f7ff 21 float TMP36::read()
4180_1 2:58d85409f7ff 22 {
4180_1 2:58d85409f7ff 23 //convert sensor reading to temperature in degrees C
4180_1 2:58d85409f7ff 24 return ((_pin.read()*3.3)-0.500)*100.0;
4180_1 2:58d85409f7ff 25 }
4180_1 2:58d85409f7ff 26 //overload of float conversion (avoids needing to type .read() in equations)
4180_1 2:58d85409f7ff 27 TMP36::operator float ()
4180_1 2:58d85409f7ff 28 {
4180_1 2:58d85409f7ff 29 //convert sensor reading to temperature in degrees C
4180_1 2:58d85409f7ff 30 return ((_pin.read()*3.3)-0.500)*100.0;
4180_1 2:58d85409f7ff 31 }