Simple analog input and LCD 4 bit Example reading a LM35. Tested in BluePill board

Dependencies:   mbed TextLCD

Committer:
dscarnatto
Date:
Tue Jul 28 09:20:47 2020 +0000
Revision:
2:93417af6f469
Parent:
1:e10c603cf0ae
first commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:271d74b09d64 1 /* Hello World! for the TextLCD Enhanced Library*/
dscarnatto 2:93417af6f469 2 //Probado en el BluePill 27/07/20
hudakz 0:271d74b09d64 3
hudakz 0:271d74b09d64 4 #include "mbed.h"
hudakz 0:271d74b09d64 5 #include "TextLCD.h"
hudakz 0:271d74b09d64 6
hudakz 1:e10c603cf0ae 7 // Host PC Communication channels
dscarnatto 2:93417af6f469 8 //Serial pc(PA_2, PA_3); // tx, rx
dscarnatto 2:93417af6f469 9 AnalogIn LM35(PA_7);
hudakz 1:e10c603cf0ae 10 // LCD instantiation
dscarnatto 2:93417af6f469 11 TextLCD lcd(PB_4, PB_3, PB_12, PB_13, PB_14, PB_15, TextLCD::LCD20x4); // 4-bit bus: RS, E, D4, D5, D6, D7
hudakz 1:e10c603cf0ae 12 Timer t;
hudakz 0:271d74b09d64 13
hudakz 0:271d74b09d64 14 int main()
hudakz 1:e10c603cf0ae 15 {
dscarnatto 2:93417af6f469 16 //pc.printf("TextLCD Enhanced Test. Columns=%d, Rows=%d\n\r", lcd.columns(), lcd.rows());
dscarnatto 2:93417af6f469 17 lcd.printf("Funka locoso");
dscarnatto 2:93417af6f469 18 float tempC,tempF,a[10],avg;
dscarnatto 2:93417af6f469 19 int i;
dscarnatto 2:93417af6f469 20 lcd.locate(0,1);
dscarnatto 2:93417af6f469 21 while(1) {
hudakz 0:271d74b09d64 22
dscarnatto 2:93417af6f469 23 avg=0;
dscarnatto 2:93417af6f469 24 //Toma 10 lecturas del LM35
dscarnatto 2:93417af6f469 25 for(i=0; i<10; i++) {
dscarnatto 2:93417af6f469 26 a[i]=LM35.read();
dscarnatto 2:93417af6f469 27 wait(.02);
hudakz 0:271d74b09d64 28 }
dscarnatto 2:93417af6f469 29 //Calcula el promedio
dscarnatto 2:93417af6f469 30 for(i=0; i<10; i++) {
dscarnatto 2:93417af6f469 31 avg=avg+(a[i]/10);
dscarnatto 2:93417af6f469 32 }
dscarnatto 2:93417af6f469 33 //Ajusta conversion
hudakz 0:271d74b09d64 34
dscarnatto 2:93417af6f469 35 tempC=(avg*3.685503686*100);
dscarnatto 2:93417af6f469 36 tempF=(9.0*tempC)/5.0 + 32.0;
dscarnatto 2:93417af6f469 37 //Imprime en LCD
dscarnatto 2:93417af6f469 38 lcd.printf("Temp = %.0f C -> %.0f F\r\n", tempC,tempF);
hudakz 0:271d74b09d64 39
dscarnatto 2:93417af6f469 40 wait(1);
dscarnatto 2:93417af6f469 41 lcd.locate(0,1);
dscarnatto 2:93417af6f469 42 }
hudakz 0:271d74b09d64 43 }