Program reads temperature from internal thermo meter and voltage on A0. Both values are displayed on LCD
Dependencies: Freetronics_16x2_LCD mbed
Fork of Freetronics_16x2_LCD by
Revision 3:8ed2cd310fa7, committed 2015-01-31
- Comitter:
- jirik09
- Date:
- Sat Jan 31 15:53:05 2015 +0000
- Parent:
- 2:4e0ed7dc6420
- Commit message:
- Just test
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 4e0ed7dc6420 -r 8ed2cd310fa7 main.cpp --- a/main.cpp Fri Jul 25 12:18:06 2014 +0000 +++ b/main.cpp Sat Jan 31 15:53:05 2015 +0000 @@ -19,24 +19,69 @@ #include "mbed.h" #include "freetronicsLCDShield.h" -freetronicsLCDShield lcd(D8, D9, D4, D5, D6, D7, D3, A0); +Serial pc(SERIAL_TX, SERIAL_RX); + +DigitalOut myled(LED1); +AnalogIn analog_value(A0); -int main() { +#define MV(x) ((0xFFF*x)/3300) +#define V25 1.398 +#define SLOPE 0.0043 + +int main() +{ + wait(0.1); + + freetronicsLCDShield lcd(D6, D7, D2, D3, D4, D5, D8, A1); // turn on the back light (it's off by default) lcd.setBackLight(true); + + + + + + // print the first line and wait 3 sec - lcd.printf("mbed application"); - wait(3); + lcd.cls(); + + int i = 1; + float meas=0; + float LP=0.025; + float LPT=0.0025; + float temp=0; + lcd.setCursorPosition(0, 0); + lcd.printf("Napeti"); + ADC1->CR2|=ADC_CR2_TSVREFE; + while(1) { + meas = LP*analog_value.read()+(1-LP)*meas; // Converts and read the analog input value + + ADC_RegularChannelConfig(ADC1, 16, 1, ADC_SampleTime_7Cycles5); - // print the counter prefix; the number will be printed in the while loop - lcd.setCursorPosition(1, 0); - lcd.printf("counter"); - - int i=1; - while (i++) { - lcd.setCursorPosition(1, 8); - lcd.printf("%d", i); + //// Temperature (in °C) = {(V25 - VSENSE) / Avg_Slope} + 25. + //v25 = 1.43 + //avg_slope 4.3mv/c + + ADC_SoftwareStartConvCmd(ADC1, ENABLE); // Start conversion + + while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); // Wait end of conversion + + temp= LPT*((V25-(float)(ADC_GetConversionValue(ADC1))*3.3/4096)/SLOPE+25)+(1-LPT)*temp; // Get conversion value + + + if(meas > 0.5) { // If the value is greater than 1000 mV toggle the LED + myled = 1; + } else { + myled = 0; + } + i++; + if(i==200) { + i=0; + lcd.setCursorPosition(0, 0); + lcd.printf("%2.2f C ", temp); + lcd.setCursorPosition(1, 0); + lcd.printf("%1.4f V", meas*3.3); + } wait(0.001); } }