BarGraph

Dependencies:   mbed

Committer:
Wizo
Date:
Thu Nov 15 17:23:34 2018 +0000
Revision:
0:a4839c6a1bf5
BarGraph

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wizo 0:a4839c6a1bf5 1 #include "mbed.h"
Wizo 0:a4839c6a1bf5 2 #include "C12832.h"
Wizo 0:a4839c6a1bf5 3
Wizo 0:a4839c6a1bf5 4 C12832 lcd(p5, p7, p6, p8, p11); // LCD mit 128 x 32 Pixel
Wizo 0:a4839c6a1bf5 5 AnalogIn aiPoti1(p19);
Wizo 0:a4839c6a1bf5 6
Wizo 0:a4839c6a1bf5 7 int main()
Wizo 0:a4839c6a1bf5 8 {
Wizo 0:a4839c6a1bf5 9 float poti1Wert;
Wizo 0:a4839c6a1bf5 10 lcd.cls(); // löscht lcd (clear screen)
Wizo 0:a4839c6a1bf5 11 lcd.locate(0,0); // x-position, y-position (x: 0-127; y: 0-31)
Wizo 0:a4839c6a1bf5 12 lcd.printf("Wert vom Poti 1:");
Wizo 0:a4839c6a1bf5 13 while(1) {
Wizo 0:a4839c6a1bf5 14 lcd.locate(0,10);
Wizo 0:a4839c6a1bf5 15 poti1Wert = aiPoti1.read();
Wizo 0:a4839c6a1bf5 16 lcd.printf("Spannung 1 = %5.3f V", poti1Wert*3.3);
Wizo 0:a4839c6a1bf5 17 // Balkengraph: linker oberer Punkt (Pixelnummer): x=0, y=20;
Wizo 0:a4839c6a1bf5 18 // rechter unterer Punkt: x=(int)(poti1Wert*127), y=28; letzter Parameter = 1 = schwarz
Wizo 0:a4839c6a1bf5 19 lcd.fillrect(0, 20, (int)(poti1Wert*127), 28, 1);
Wizo 0:a4839c6a1bf5 20 // Löschen des restlichen Bereichs bis zum Ende des Displays; ist notwendig, weil der aktuelle
Wizo 0:a4839c6a1bf5 21 // Balken kann ja auch kürzer sein als der zuvor geschriebene Balken!
Wizo 0:a4839c6a1bf5 22 lcd.fillrect((int)(poti1Wert*127)+1, 20, 127, 28, 0); // 0 = transparent (Hintergrundfarbe)
Wizo 0:a4839c6a1bf5 23 lcd.copy_to_lcd(); // erzwingt sofortiges Anzeigen am LCD
Wizo 0:a4839c6a1bf5 24 wait_ms(100);
Wizo 0:a4839c6a1bf5 25 }
Wizo 0:a4839c6a1bf5 26 }