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.
main.cpp@0:1e4bca77e18e, 2015-06-15 (annotated)
- Committer:
- parth1100
- Date:
- Mon Jun 15 08:37:39 2015 +0000
- Revision:
- 0:1e4bca77e18e
lm35 moving avg
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| parth1100 | 0:1e4bca77e18e | 1 | #include "mbed.h" |
| parth1100 | 0:1e4bca77e18e | 2 | #include "TextLCD.h" |
| parth1100 | 0:1e4bca77e18e | 3 | #include "stdio.h" |
| parth1100 | 0:1e4bca77e18e | 4 | AnalogIn ain(PTC2); |
| parth1100 | 0:1e4bca77e18e | 5 | TextLCD lcd(PTA1,PTA2,PTD4,PTA12,PTA4,PTA5,TextLCD::LCD16x2); |
| parth1100 | 0:1e4bca77e18e | 6 | DigitalOut ground(PTC9); |
| parth1100 | 0:1e4bca77e18e | 7 | char buff[15]={'\0'}; |
| parth1100 | 0:1e4bca77e18e | 8 | |
| parth1100 | 0:1e4bca77e18e | 9 | int main() |
| parth1100 | 0:1e4bca77e18e | 10 | { |
| parth1100 | 0:1e4bca77e18e | 11 | ground=0; |
| parth1100 | 0:1e4bca77e18e | 12 | lcd.cls(); |
| parth1100 | 0:1e4bca77e18e | 13 | while(1) |
| parth1100 | 0:1e4bca77e18e | 14 | { |
| parth1100 | 0:1e4bca77e18e | 15 | float temp[70]={0},volt[100]={0};//arrey for temp & vltg |
| parth1100 | 0:1e4bca77e18e | 16 | int i=0, j=0; |
| parth1100 | 0:1e4bca77e18e | 17 | |
| parth1100 | 0:1e4bca77e18e | 18 | for(i=0;i<100;i++) |
| parth1100 | 0:1e4bca77e18e | 19 | { |
| parth1100 | 0:1e4bca77e18e | 20 | volt[i]=ain*3.3; |
| parth1100 | 0:1e4bca77e18e | 21 | } |
| parth1100 | 0:1e4bca77e18e | 22 | for(i=0;i<70;i++) |
| parth1100 | 0:1e4bca77e18e | 23 | { |
| parth1100 | 0:1e4bca77e18e | 24 | float avg = 0.0; //initialise avg |
| parth1100 | 0:1e4bca77e18e | 25 | |
| parth1100 | 0:1e4bca77e18e | 26 | for(j=i;j<(i+20);j++) //taking first 20 reading |
| parth1100 | 0:1e4bca77e18e | 27 | { |
| parth1100 | 0:1e4bca77e18e | 28 | avg = avg +volt[j]; |
| parth1100 | 0:1e4bca77e18e | 29 | } |
| parth1100 | 0:1e4bca77e18e | 30 | avg = avg/20.0; //taking avg of 20 readings |
| parth1100 | 0:1e4bca77e18e | 31 | temp[i] = avg*100.0; // calibrating temp with 10mV / degree C |
| parth1100 | 0:1e4bca77e18e | 32 | } |
| parth1100 | 0:1e4bca77e18e | 33 | //initialization of lcd |
| parth1100 | 0:1e4bca77e18e | 34 | lcd.cls(); |
| parth1100 | 0:1e4bca77e18e | 35 | for(i=0;i<70;i++) |
| parth1100 | 0:1e4bca77e18e | 36 | { |
| parth1100 | 0:1e4bca77e18e | 37 | lcd.locate(0,0); |
| parth1100 | 0:1e4bca77e18e | 38 | lcd.printf("Vtg:"); |
| parth1100 | 0:1e4bca77e18e | 39 | lcd.locate(7,0); |
| parth1100 | 0:1e4bca77e18e | 40 | sprintf(buff,"%.2f",volt[i]); |
| parth1100 | 0:1e4bca77e18e | 41 | lcd.printf(buff); |
| parth1100 | 0:1e4bca77e18e | 42 | lcd.locate(0,1); |
| parth1100 | 0:1e4bca77e18e | 43 | lcd.printf("Temp:"); |
| parth1100 | 0:1e4bca77e18e | 44 | sprintf(buff,"%.2f",temp[i]); |
| parth1100 | 0:1e4bca77e18e | 45 | lcd.printf(buff); |
| parth1100 | 0:1e4bca77e18e | 46 | wait(0.5); |
| parth1100 | 0:1e4bca77e18e | 47 | } |
| parth1100 | 0:1e4bca77e18e | 48 | } |
| parth1100 | 0:1e4bca77e18e | 49 | } |