TINF_MittelwerteUeberwachung

Dependencies:   mbed

Committer:
martwerl
Date:
Thu Nov 15 18:24:11 2018 +0000
Revision:
0:fb8791842ef8
TINF_MittelwerteUeberwachung

Who changed what in which revision?

UserRevisionLine numberNew contents of line
martwerl 0:fb8791842ef8 1 // Beispiel Mittelwerte
martwerl 0:fb8791842ef8 2 // Peter Beck - 16.04.2018
martwerl 0:fb8791842ef8 3
martwerl 0:fb8791842ef8 4 #include "mbed.h"
martwerl 0:fb8791842ef8 5 #include "C12832.h"
martwerl 0:fb8791842ef8 6
martwerl 0:fb8791842ef8 7 C12832 lcd(p5, p7, p6, p8, p11);
martwerl 0:fb8791842ef8 8 AnalogIn aiPoti1(p19);
martwerl 0:fb8791842ef8 9
martwerl 0:fb8791842ef8 10 DigitalIn diDown(p12);
martwerl 0:fb8791842ef8 11 DigitalIn diUp(p15);
martwerl 0:fb8791842ef8 12 InterruptIn iiDown(p12);
martwerl 0:fb8791842ef8 13 InterruptIn iiUp(p15);
martwerl 0:fb8791842ef8 14
martwerl 0:fb8791842ef8 15 //AnalogIn aiPoti2(p20);
martwerl 0:fb8791842ef8 16 Timeout BlinkTimeoutTmr;
martwerl 0:fb8791842ef8 17
martwerl 0:fb8791842ef8 18 Ticker toreadPoti1;
martwerl 0:fb8791842ef8 19
martwerl 0:fb8791842ef8 20 float poti1Wert;
martwerl 0:fb8791842ef8 21 float poti1Durchschnitt;
martwerl 0:fb8791842ef8 22 float poti1Array[10];
martwerl 0:fb8791842ef8 23
martwerl 0:fb8791842ef8 24 int slot = 0;
martwerl 0:fb8791842ef8 25 int mode = 0; //Messmodus
martwerl 0:fb8791842ef8 26 BusOut doLeds(LED1,LED2,LED3,LED4);
martwerl 0:fb8791842ef8 27
martwerl 0:fb8791842ef8 28
martwerl 0:fb8791842ef8 29 // functions
martwerl 0:fb8791842ef8 30
martwerl 0:fb8791842ef8 31 void BlinkTimeout()
martwerl 0:fb8791842ef8 32 {
martwerl 0:fb8791842ef8 33 doLeds = 0;
martwerl 0:fb8791842ef8 34 }
martwerl 0:fb8791842ef8 35
martwerl 0:fb8791842ef8 36 void readPoti1()
martwerl 0:fb8791842ef8 37 {
martwerl 0:fb8791842ef8 38 // Poti-Wert auslesen
martwerl 0:fb8791842ef8 39 poti1Wert = 3.3 * aiPoti1.read();
martwerl 0:fb8791842ef8 40
martwerl 0:fb8791842ef8 41 poti1Array[slot] = poti1Wert;
martwerl 0:fb8791842ef8 42
martwerl 0:fb8791842ef8 43 slot++;
martwerl 0:fb8791842ef8 44 if (slot>9) slot = 0;
martwerl 0:fb8791842ef8 45
martwerl 0:fb8791842ef8 46 // Ausgabe:
martwerl 0:fb8791842ef8 47
martwerl 0:fb8791842ef8 48
martwerl 0:fb8791842ef8 49 poti1Durchschnitt = 0;
martwerl 0:fb8791842ef8 50 for (int i=0; i<10; i++) {
martwerl 0:fb8791842ef8 51 poti1Durchschnitt += poti1Array[slot];
martwerl 0:fb8791842ef8 52 }
martwerl 0:fb8791842ef8 53 poti1Durchschnitt /= 10;
martwerl 0:fb8791842ef8 54
martwerl 0:fb8791842ef8 55 lcd.locate(0,0);
martwerl 0:fb8791842ef8 56 lcd.printf("Spannung aktuell = %5.3f V", poti1Wert); // Schreibe..
martwerl 0:fb8791842ef8 57 lcd.locate(0,10); // Setze Cursor auf X=0, Y=10
martwerl 0:fb8791842ef8 58
martwerl 0:fb8791842ef8 59 lcd.printf("Spannung gerundet = %5.3f V", poti1Durchschnitt); // Schreibe..
martwerl 0:fb8791842ef8 60 lcd.fillrect(0, 20, (int)(poti1Wert*128/3.3), 24, 1); // Schreibe Block mit X=0,Y=20, X2=(errechnet), Y2=28 in der Farbe 1
martwerl 0:fb8791842ef8 61 lcd.fillrect(0, 25, (int)(poti1Durchschnitt*128/3.3), 28, 1); // Schreibe Block mit X=0,Y=20, X2=(errechnet), Y2=28 in der Farbe 1
martwerl 0:fb8791842ef8 62
martwerl 0:fb8791842ef8 63 lcd.fillrect((int)(poti1Durchschnitt*128/3.3), 20, 128, 28, 0); // Schreibe eine weissen Block auf der restlichen Fläche in der Farbe 1
martwerl 0:fb8791842ef8 64 lcd.copy_to_lcd();
martwerl 0:fb8791842ef8 65
martwerl 0:fb8791842ef8 66 }
martwerl 0:fb8791842ef8 67
martwerl 0:fb8791842ef8 68
martwerl 0:fb8791842ef8 69
martwerl 0:fb8791842ef8 70 int main()
martwerl 0:fb8791842ef8 71 {
martwerl 0:fb8791842ef8 72
martwerl 0:fb8791842ef8 73 lcd.cls(); // löscht lcd (clear screen)
martwerl 0:fb8791842ef8 74 lcd.locate(0,10); // Setze Cursor auf X=0, Y=10
martwerl 0:fb8791842ef8 75 lcd.printf("Willkommen!");
martwerl 0:fb8791842ef8 76 lcd.copy_to_lcd();
martwerl 0:fb8791842ef8 77 wait_ms(300);
martwerl 0:fb8791842ef8 78
martwerl 0:fb8791842ef8 79 // Erstellung von 2 Arrays für die gleitende Mittelwertbildung
martwerl 0:fb8791842ef8 80 // 2 Hz mit Ticker realisieren
martwerl 0:fb8791842ef8 81 lcd.cls(); // löscht lcd (clear screen)
martwerl 0:fb8791842ef8 82 lcd.locate(0,0); // x-position, y-position (x: 0-128; y: 0-32)
martwerl 0:fb8791842ef8 83 lcd.printf("Werte von Poti 1 und 2:");
martwerl 0:fb8791842ef8 84
martwerl 0:fb8791842ef8 85 toreadPoti1.attach(&readPoti1, 0.5);
martwerl 0:fb8791842ef8 86
martwerl 0:fb8791842ef8 87
martwerl 0:fb8791842ef8 88 while(1) {
martwerl 0:fb8791842ef8 89
martwerl 0:fb8791842ef8 90 }
martwerl 0:fb8791842ef8 91 }
martwerl 0:fb8791842ef8 92
martwerl 0:fb8791842ef8 93