Grove Temp sensor Hello world example
Dependencies: Grove_temp_sensor mbed
Revision 3:056a7a65f807, committed 2016-03-10
- Comitter:
- peipei123
- Date:
- Thu Mar 10 19:42:29 2016 +0000
- Parent:
- 2:772a59579086
- Commit message:
- 1
Changed in this revision
diff -r 772a59579086 -r 056a7a65f807 Grove_temp_sensor.h --- a/Grove_temp_sensor.h Thu Mar 10 19:08:46 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -#include "mbed.h" - -//Setup a new class for Grove_temp_sensor sensor -class Grove_temp_sensor -{ -public: - /** Read the servo motors current position - * - * @param returns A normalised number 0.0-1.0 representing the full range. - */ - Grove_temp_sensor(PinName pin); - /** Read the servo motors current position - * - * @param returns A normalised number 0.0-1.0 representing the full range. - */ - Grove_temp_sensor(); - /** Read the servo motors current position - * - * @param returns A normalised number 0.0-1.0 representing the full range. - */ - float read(); -private: -//class sets up the AnalogIn pin - AnalogIn _pin; -}; - -Grove_temp_sensor::Grove_temp_sensor(PinName pin) : _pin(pin) -{ -// _pin(pin) means pass pin to the AnalogIn constructor -} - -float Grove_temp_sensor::read() -{ - - double a; - a=_pin.read()*1023; - double resistance=(float)(1023-a)*10000/a; - double temperature=1/(log(resistance/10000)/3975+1/298.15)-276.05; - //conver C to F; - temperature = (9.0*temperature)/5.0 + 32.0; - return temperature; -} - - - \ No newline at end of file
diff -r 772a59579086 -r 056a7a65f807 Grove_temp_sensor.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Grove_temp_sensor.lib Thu Mar 10 19:42:29 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/peipei123/code/Grove_temp_sensor/#b7d0479535ab
diff -r 772a59579086 -r 056a7a65f807 main.cpp --- a/main.cpp Thu Mar 10 19:08:46 2016 +0000 +++ b/main.cpp Thu Mar 10 19:42:29 2016 +0000 @@ -1,11 +1,16 @@ #include "mbed.h" #include "Grove_temp_sensor.h" +// This is the hello world example how to use this sensor + +//creat sensor object Grove_temp_sensor input(p15); +//set up usb serial port Serial pc(USBTX, USBRX); int main() { double temp; while(1) { - temp = input.read(); + //read the temperature here + temp = input.read_F(); printf("The temperature is: %5.2F F \n\r", temp); wait(0.5); }