Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mAIn_barGraph.cpp@0:f0bb7332032f, 2018-11-15 (annotated)
- Committer:
- martwerl
- Date:
- Thu Nov 15 18:04:45 2018 +0000
- Revision:
- 0:f0bb7332032f
mbedAnalogIn
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| martwerl | 0:f0bb7332032f | 1 | #include "mbed.h" |
| martwerl | 0:f0bb7332032f | 2 | #include "C12832.h" |
| martwerl | 0:f0bb7332032f | 3 | |
| martwerl | 0:f0bb7332032f | 4 | C12832 lcd(p5, p7, p6, p8, p11); // LCD mit 128 x 32 Pixel |
| martwerl | 0:f0bb7332032f | 5 | AnalogIn aiPoti1(p19); |
| martwerl | 0:f0bb7332032f | 6 | |
| martwerl | 0:f0bb7332032f | 7 | int main() { |
| martwerl | 0:f0bb7332032f | 8 | float poti1Wert; |
| martwerl | 0:f0bb7332032f | 9 | lcd.cls(); // löscht lcd (clear screen) |
| martwerl | 0:f0bb7332032f | 10 | lcd.locate(0,0); // x-position, y-position (x: 0-127; y: 0-31) |
| martwerl | 0:f0bb7332032f | 11 | lcd.printf("Wert vom Poti 1:"); |
| martwerl | 0:f0bb7332032f | 12 | while(1) { |
| martwerl | 0:f0bb7332032f | 13 | lcd.locate(0,10); |
| martwerl | 0:f0bb7332032f | 14 | poti1Wert = aiPoti1.read(); |
| martwerl | 0:f0bb7332032f | 15 | lcd.printf("Spannung 1 = %5.3f V", poti1Wert*3.3); |
| martwerl | 0:f0bb7332032f | 16 | // Balkengraph: linker oberer Punkt (Pixelnummer): x=0, y=20; |
| martwerl | 0:f0bb7332032f | 17 | // rechter unterer Punkt: x=(int)(poti1Wert*127), y=28; letzter Parameter = 1 = schwarz |
| martwerl | 0:f0bb7332032f | 18 | lcd.fillrect(0, 20, (int)(poti1Wert*127), 28, 1); |
| martwerl | 0:f0bb7332032f | 19 | // Löschen des restlichen Bereichs bis zum Ende des Displays; ist notwendig, weil der aktuelle |
| martwerl | 0:f0bb7332032f | 20 | // Balken kann ja auch kürzer sein als der zuvor geschriebene Balken! |
| martwerl | 0:f0bb7332032f | 21 | lcd.fillrect((int)(poti1Wert*127)+1, 20, 127, 28, 0); // 0 = transparent (Hintergrundfarbe) |
| martwerl | 0:f0bb7332032f | 22 | lcd.copy_to_lcd(); // erzwingt sofortiges Anzeigen am LCD |
| martwerl | 0:f0bb7332032f | 23 | wait_ms(100); |
| martwerl | 0:f0bb7332032f | 24 | } |
| martwerl | 0:f0bb7332032f | 25 | } |