Temperature + Digital Disapley
Dependencies: DigitDisplay mbed
Fork of Grove_Thermometer by
main.cpp
00001 /* Grove - Temprature Sensor demo v1.0 00002 * This sensor detects the enviroment temprature, 00003 * Uses a Arch-Pro board with Grove Base Shield 00004 * Connect the Grove Temperature sensor to A0 and 00005 * connect a Grove 4 digit LED display to the UART connector 00006 * The temperature will be displayed in Celcius 00007 * Modified by David Bottrill from the original Arduino code 00008 * Reference: http://www.seeedstudio.com 00009 */ 00010 00011 #include "mbed.h" 00012 #include "DigitDisplay.h" 00013 00014 DigitalOut myled(LED2); 00015 00016 DigitDisplay display(P4_29, P4_28); 00017 AnalogIn ain(P0_23); 00018 00019 int a; 00020 float temperature; 00021 int B=3975; //B value of the thermistor 00022 float resistance; 00023 00024 int main() 00025 { 00026 while(1) { 00027 // multiply ain by 675 if the Grove shield is set to 5V or 1023 if set to 3.3V 00028 a=ain*675; 00029 resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor; 00030 temperature=1/(log(resistance/10000)/B+1/298.15)-273.15; //convert to temperature via datasheet ; 00031 myled = 1; 00032 wait(0.8); 00033 myled = 0; 00034 wait(0.8); 00035 display.write(temperature); 00036 } 00037 } 00038 00039
Generated on Tue Jul 12 2022 18:20:08 by 1.7.2