checking temp and lighting
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 Serial pc(USBTX,USBRX); 00004 DigitalOut firstLED(LED1); 00005 DigitalOut secondLED(LED2); 00006 DigitalOut thirdLED(LED3); 00007 DigitalOut fourthLED(LED4); 00008 AnalogIn Thermistor(p19); 00009 AnalogIn Photocell(p20); 00010 Ticker Input; 00011 InterruptIn button(p17); //Interrupt from button 00012 Timer debounce; 00013 float TempV,PhotoV,T,CellV,TempStart,TempDiff; 00014 int Rs=10; //Resistor Resistance 00015 void Temp() 00016 { 00017 TempV=3.3*Thermistor.read(); 00018 pc.printf("TempV = %f\r\n",TempV); 00019 T=-1481.96+sqrt(2196200 + ((1.839-float(TempV))/.00000388)); 00020 pc.printf("Temp = %3.2f C\r\n",T); 00021 TempDiff=T-TempStart; // Temp Compare 00022 if (TempDiff<0.0) { 00023 if (TempDiff<-1) { 00024 firstLED=1; 00025 secondLED=0; 00026 thirdLED=0; 00027 } else { 00028 firstLED=1; 00029 secondLED=1; 00030 thirdLED=0; 00031 } 00032 } 00033 if (TempDiff>0.0) { 00034 if(TempDiff<1) { 00035 firstLED=1; 00036 secondLED=1; 00037 thirdLED=0; 00038 } else { 00039 firstLED=1; 00040 secondLED=1; 00041 thirdLED=1; 00042 } 00043 00044 } 00045 } 00046 void Photo() 00047 { 00048 PhotoV=3.3*Photocell.read(); 00049 pc.printf("PhotoV = %f\r\n",PhotoV); 00050 CellV=3.3*float(Rs)/float(PhotoV)-float(Rs); 00051 pc.printf("Resistance = %.2f kohms\r\n",CellV); 00052 if (CellV>10) { // toggle LED 4 if covered 00053 fourthLED=1; 00054 } else { 00055 fourthLED=0; 00056 } 00057 } 00058 void UpdateTemp() //button reset inital temp 00059 { 00060 if (debounce.read_ms()>200) { // debouce check for button press 00061 TempV=3.3*Thermistor.read(); 00062 TempStart=-1481.96+sqrt(2196200 + ((1.839-float(TempV))/.00000388)); 00063 pc.printf("Reference Temp = %.2f\r\n", TempStart); 00064 debounce.reset(); 00065 } 00066 } 00067 void Run() 00068 { 00069 Temp(); 00070 Photo(); 00071 } 00072 int main() 00073 { 00074 Input.attach(Run,1); 00075 debounce.start(); 00076 button.rise(&UpdateTemp); 00077 TempV=3.3*Thermistor.read(); 00078 TempStart=-1481.96+sqrt(2196200 + ((1.839-float(TempV))/.00000388)); 00079 00080 while(1) { 00081 00082 } 00083 }
Generated on Thu Dec 1 2022 14:47:33 by
1.7.2
