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.
Dependencies: EALib I2S LM75B SDFileSystem mbed
TestTemperature.cpp
00001 /* 00002 * Copyright 2013 Embedded Artists AB 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 /****************************************************************************** 00018 * Includes 00019 *****************************************************************************/ 00020 00021 #include "mbed.h" 00022 #include "TestTemperature.h" 00023 #include "LM75B.h" 00024 00025 /****************************************************************************** 00026 * Defines and typedefs 00027 *****************************************************************************/ 00028 00029 #define MIN_TEMP (15.0f) 00030 #define MAX_TEMP (45.0f) 00031 00032 /****************************************************************************** 00033 * Public Functions 00034 *****************************************************************************/ 00035 00036 /* 00037 Prerequisites: 00038 00039 - For this test to work jumpers JP8 and JP9 on the LPC4088 Experiment Base Board 00040 must both be in positions 1-2 00041 */ 00042 00043 bool TestTemperature::runTest() { 00044 //Create an LM75B object at 0x92/0x93 (ADDRESS_1) 00045 LM75B sensor(P0_27, P0_28, LM75B::ADDRESS_1); 00046 00047 printf("Testing LM75 temperature sensor...\n"); 00048 00049 // Test waits up to 5 seconds, sampling the temperature twice per second, 00050 // for the sensor to produce a value in the MIN_TEMP to MAX_TEMP range. 00051 00052 if (sensor.open()) { 00053 printf("LM75 Device detected!\n"); 00054 00055 int i = 10; 00056 while (i--) { 00057 float f = (float)sensor; 00058 00059 printf("Temp = %.3f\n", f); 00060 00061 if ((f >= MIN_TEMP) && (f <= MAX_TEMP)) { 00062 printf("Temp in %.3f..%.3f range - test passed\n", MIN_TEMP, MAX_TEMP); 00063 return true; 00064 } 00065 00066 //Sleep for 0.5 seconds 00067 wait(0.5); 00068 } 00069 if (i == 0) { 00070 printf("LM75 No temp in range %.3f..%.3f!\n", MIN_TEMP, MAX_TEMP); 00071 } 00072 } else { 00073 printf("LM75 Device not detected!\n"); 00074 } 00075 return false; 00076 } 00077 00078
Generated on Sun Jul 17 2022 08:29:10 by
1.7.2