Belmin Mustajbašić
/
US2016_LV3_Z1
Mirza i Belmin
Fork of US2016_LV3_Z1 by
Revision 1:96f27c31a52b, committed 2017-03-28
- Comitter:
- 2017US_BelminM
- Date:
- Tue Mar 28 16:34:53 2017 +0000
- Parent:
- 0:6ebfd28a8b0c
- Commit message:
- Mirza Mesihovic; Belmin Mustajbasic; Lv3
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 6ebfd28a8b0c -r 96f27c31a52b main.cpp --- a/main.cpp Wed Mar 09 08:30:01 2016 +0000 +++ b/main.cpp Tue Mar 28 16:34:53 2017 +0000 @@ -1,22 +1,83 @@ #include "mbed.h" #include "N5110.h" + + #define dp23 P0_0 +#define NUMOFMEASURES 15 + +DigitalIn switchButton(dp1); +DigitalOut enable(dp14); +AnalogIn aIn(dp9); +N5110 display(dp4, dp24, dp23, dp25, dp2, dp6, dp18); + +int measureType(0), measureNum(0); +float measured[NUMOFMEASURES], avg(0); -//N5110 lcd(VCC,SCE,RST,DC,MOSI,SCLK,LED)); -N5110 lcd(dp4,dp24,dp23,dp25,dp2,dp6,dp18); +void Button() +{ + static int oldValue(0); + + if(oldValue == 0 && switchButton == 1) + measureType++; + if(measureType==2) measureType = 0; + + oldValue = switchButton; +} -DigitalOut enable(dp14); - -int main() { +void TakeMeasure() +{ + if(measureNum < NUMOFMEASURES) + { + measured[measureNum] = aIn; + measureNum++; + return; + } + + float sumOfMeasures(0); + for(int i = 0; i < NUMOFMEASURES - 1; i++) + { + measured[i] = measured[i+1]; + sumOfMeasures+=measured[i]; + } - //deaktivacija led dioda - enable=1; + measured[measureNum- 1] = aIn; + sumOfMeasures+=aIn; + avg = sumOfMeasures / NUMOFMEASURES; +} + +void RefreshDisplay() +{ + char placeholder[10]; + - //inicijalizacija displeja - lcd.init(); + if(measureType == 0) + { + sprintf(placeholder, "%.2f V", (avg * 3.3)); + }else if (measureType == 1) + { + sprintf(placeholder, "%.2f Ohm", (10000*(avg))); + } + + display.printString(" ", 0, 0); + display.printString(placeholder, 0, 0); - //prikaz stringa - lcd.printString("Mi volimo US!",0,0); + +} + + +int main() +{ + enable = 1; + display.init(); - while(1); + display.printString("Agent 16796", 0 , 2); + display.printString("Agent 17345", 0 , 3); + while(1) { + Button(); + TakeMeasure(); + RefreshDisplay(); + wait(0.1); + } + + return 0; }