x

Committer:
zchen311
Date:
Tue Feb 12 06:23:02 2013 +0000
Revision:
0:ab3d7d0c34ce
test2, has pb to change state, and mode setting. ; 1. adding cooling (done); 2. sensor log; 3.speaker; 4.pushbutton(done); 5. RGB

Who changed what in which revision?

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