Mirza i Belmin

Dependencies:   N5110 mbed

Fork of US2016_LV3_Z1 by Emir Sokic

Committer:
2017US_BelminM
Date:
Tue Mar 28 16:34:53 2017 +0000
Revision:
1:96f27c31a52b
Parent:
0:6ebfd28a8b0c
Mirza Mesihovic; Belmin Mustajbasic; Lv3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
esokic 0:6ebfd28a8b0c 1 #include "mbed.h"
esokic 0:6ebfd28a8b0c 2 #include "N5110.h"
2017US_BelminM 1:96f27c31a52b 3
2017US_BelminM 1:96f27c31a52b 4
esokic 0:6ebfd28a8b0c 5 #define dp23 P0_0
2017US_BelminM 1:96f27c31a52b 6 #define NUMOFMEASURES 15
2017US_BelminM 1:96f27c31a52b 7
2017US_BelminM 1:96f27c31a52b 8 DigitalIn switchButton(dp1);
2017US_BelminM 1:96f27c31a52b 9 DigitalOut enable(dp14);
2017US_BelminM 1:96f27c31a52b 10 AnalogIn aIn(dp9);
2017US_BelminM 1:96f27c31a52b 11 N5110 display(dp4, dp24, dp23, dp25, dp2, dp6, dp18);
2017US_BelminM 1:96f27c31a52b 12
2017US_BelminM 1:96f27c31a52b 13 int measureType(0), measureNum(0);
2017US_BelminM 1:96f27c31a52b 14 float measured[NUMOFMEASURES], avg(0);
esokic 0:6ebfd28a8b0c 15
2017US_BelminM 1:96f27c31a52b 16 void Button()
2017US_BelminM 1:96f27c31a52b 17 {
2017US_BelminM 1:96f27c31a52b 18 static int oldValue(0);
2017US_BelminM 1:96f27c31a52b 19
2017US_BelminM 1:96f27c31a52b 20 if(oldValue == 0 && switchButton == 1)
2017US_BelminM 1:96f27c31a52b 21 measureType++;
2017US_BelminM 1:96f27c31a52b 22 if(measureType==2) measureType = 0;
2017US_BelminM 1:96f27c31a52b 23
2017US_BelminM 1:96f27c31a52b 24 oldValue = switchButton;
2017US_BelminM 1:96f27c31a52b 25 }
esokic 0:6ebfd28a8b0c 26
2017US_BelminM 1:96f27c31a52b 27 void TakeMeasure()
2017US_BelminM 1:96f27c31a52b 28 {
2017US_BelminM 1:96f27c31a52b 29 if(measureNum < NUMOFMEASURES)
2017US_BelminM 1:96f27c31a52b 30 {
2017US_BelminM 1:96f27c31a52b 31 measured[measureNum] = aIn;
2017US_BelminM 1:96f27c31a52b 32 measureNum++;
2017US_BelminM 1:96f27c31a52b 33 return;
2017US_BelminM 1:96f27c31a52b 34 }
2017US_BelminM 1:96f27c31a52b 35
2017US_BelminM 1:96f27c31a52b 36 float sumOfMeasures(0);
2017US_BelminM 1:96f27c31a52b 37 for(int i = 0; i < NUMOFMEASURES - 1; i++)
2017US_BelminM 1:96f27c31a52b 38 {
2017US_BelminM 1:96f27c31a52b 39 measured[i] = measured[i+1];
2017US_BelminM 1:96f27c31a52b 40 sumOfMeasures+=measured[i];
2017US_BelminM 1:96f27c31a52b 41 }
esokic 0:6ebfd28a8b0c 42
2017US_BelminM 1:96f27c31a52b 43 measured[measureNum- 1] = aIn;
2017US_BelminM 1:96f27c31a52b 44 sumOfMeasures+=aIn;
2017US_BelminM 1:96f27c31a52b 45 avg = sumOfMeasures / NUMOFMEASURES;
2017US_BelminM 1:96f27c31a52b 46 }
2017US_BelminM 1:96f27c31a52b 47
2017US_BelminM 1:96f27c31a52b 48 void RefreshDisplay()
2017US_BelminM 1:96f27c31a52b 49 {
2017US_BelminM 1:96f27c31a52b 50 char placeholder[10];
2017US_BelminM 1:96f27c31a52b 51
esokic 0:6ebfd28a8b0c 52
2017US_BelminM 1:96f27c31a52b 53 if(measureType == 0)
2017US_BelminM 1:96f27c31a52b 54 {
2017US_BelminM 1:96f27c31a52b 55 sprintf(placeholder, "%.2f V", (avg * 3.3));
2017US_BelminM 1:96f27c31a52b 56 }else if (measureType == 1)
2017US_BelminM 1:96f27c31a52b 57 {
2017US_BelminM 1:96f27c31a52b 58 sprintf(placeholder, "%.2f Ohm", (10000*(avg)));
2017US_BelminM 1:96f27c31a52b 59 }
2017US_BelminM 1:96f27c31a52b 60
2017US_BelminM 1:96f27c31a52b 61 display.printString(" ", 0, 0);
2017US_BelminM 1:96f27c31a52b 62 display.printString(placeholder, 0, 0);
esokic 0:6ebfd28a8b0c 63
2017US_BelminM 1:96f27c31a52b 64
2017US_BelminM 1:96f27c31a52b 65 }
2017US_BelminM 1:96f27c31a52b 66
2017US_BelminM 1:96f27c31a52b 67
2017US_BelminM 1:96f27c31a52b 68 int main()
2017US_BelminM 1:96f27c31a52b 69 {
2017US_BelminM 1:96f27c31a52b 70 enable = 1;
2017US_BelminM 1:96f27c31a52b 71 display.init();
esokic 0:6ebfd28a8b0c 72
2017US_BelminM 1:96f27c31a52b 73 display.printString("Agent 16796", 0 , 2);
2017US_BelminM 1:96f27c31a52b 74 display.printString("Agent 17345", 0 , 3);
2017US_BelminM 1:96f27c31a52b 75 while(1) {
2017US_BelminM 1:96f27c31a52b 76 Button();
2017US_BelminM 1:96f27c31a52b 77 TakeMeasure();
2017US_BelminM 1:96f27c31a52b 78 RefreshDisplay();
2017US_BelminM 1:96f27c31a52b 79 wait(0.1);
2017US_BelminM 1:96f27c31a52b 80 }
2017US_BelminM 1:96f27c31a52b 81
2017US_BelminM 1:96f27c31a52b 82 return 0;
esokic 0:6ebfd28a8b0c 83 }