Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Grove_Temp_Hello_world
Grove_temp_sensor.cpp@2:cf68822a48d0, 2016-03-10 (annotated)
- Committer:
- peipei123
- Date:
- Thu Mar 10 19:23:56 2016 +0000
- Revision:
- 2:cf68822a48d0
- Parent:
- 1:813f0d53a75c
- Child:
- 3:2b40039c6e54
1
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| peipei123 | 1:813f0d53a75c | 1 | #include "mbed.h" |
| peipei123 | 1:813f0d53a75c | 2 | #include "Grove_temp_sensor.h" |
| peipei123 | 1:813f0d53a75c | 3 | //Setup a new class for Grove_temp_sensor sensor |
| peipei123 | 1:813f0d53a75c | 4 | |
| peipei123 | 1:813f0d53a75c | 5 | Grove_temp_sensor::Grove_temp_sensor(PinName pin) : _pin(pin) |
| peipei123 | 1:813f0d53a75c | 6 | { |
| peipei123 | 1:813f0d53a75c | 7 | wait(0.5); |
| peipei123 | 1:813f0d53a75c | 8 | } |
| peipei123 | 1:813f0d53a75c | 9 | |
| peipei123 | 1:813f0d53a75c | 10 | float Grove_temp_sensor::read() |
| peipei123 | 1:813f0d53a75c | 11 | { |
| peipei123 | 1:813f0d53a75c | 12 | |
| peipei123 | 1:813f0d53a75c | 13 | double a; |
| peipei123 | 1:813f0d53a75c | 14 | a=ain.read()*1023; |
| peipei123 | 1:813f0d53a75c | 15 | resistance=(float)(1023-a)*10000/a; |
| peipei123 | 1:813f0d53a75c | 16 | temperature=1/(log(resistance/10000)/3975+1/298.15)-276.05; |
| peipei123 | 1:813f0d53a75c | 17 | //conver C to F; |
| peipei123 | 1:813f0d53a75c | 18 | temperature = (9.0*temperature)/5.0 + 32.0; |
| peipei123 | 1:813f0d53a75c | 19 | return temperature; |
| peipei123 | 1:813f0d53a75c | 20 | } |
Grove Temperature Sensor