Ein Balkendiagramm animieren
Visualisieren Sie einen sich ändernden Sensorwert als beweglichen Balken.
Ein Balkendiagramm animieren ist eine kostenlose Arduino & IoT Academy-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Arduino & IoT Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Arduino & IoT Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
Why a Bar Graph
Numbers are precise, but a bar tells the story instantly. A growing bar shows a rising sensor value far faster than reading digits. 📊
Start From a Reading
Animation begins with fresh data. Each loop you grab a new sensor value, for example an analogRead that lands between 0 and 1023.
int value = analogRead(A0);Map to Bar Width
The raw range rarely matches the screen. Use map to rescale 0-1023 into 0-128 pixels so the value fits your display width.
int barWidth = map(value, 0, 1023, 0, 128);Clamp the Result
A noisy reading can overshoot. Wrap it in constrain so the bar never draws past the screen edge and corrupt the layout.
barWidth = constrain(barWidth, 0, 128);Clear Each Frame
Animation is just redrawing fast. Every frame starts with clearDisplay so the old bar vanishes before the new length is drawn.
display.clearDisplay();Draw the Bar
Now paint the bar with fillRect, using your mapped width. A fixed x, y, and height keep it steady while the width breathes with the data.
display.fillRect(0, 28, barWidth, 8, WHITE);Add a Frame
Outline the full track with drawRect so users see the maximum. The fill grows inside this border, giving the bar clear context.
display.drawRect(0, 28, 128, 8, WHITE);Label the Value
Pair the bar with the exact number. Set the cursor above it and print the reading so users get both the shape and the precise figure.
display.setCursor(0, 0);
display.print(value);Push the Frame
Send the finished frame with display.display(). Because the whole buffer updates at once, the bar moves cleanly with no half-drawn flicker.
display.display();Pace the Animation
Redrawing as fast as possible looks jittery. A small delay of 50 milliseconds smooths motion and steadies a twitchy sensor reading.
delay(50);The Full Loop
Put it together: read, map, clear, draw, display, pause. That cycle in loop() is the engine behind every live OLED animation you build.
Quick Check
Your bar shows ghost trails from previous frames.
Recap
You turned readings into a live bar graph: read, map, constrain, clear, fill, frame, label, and display in a paced loop. That is real-time visualization.
Häufig gestellte Fragen
Ist die Lektion „Ein Balkendiagramm animieren“ kostenlos?
Ja — der vollständige Text von „Ein Balkendiagramm animieren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Arduino & IoT Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Arduino & IoT Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Ein Balkendiagramm animieren“?
Visualisieren Sie einen sich ändernden Sensorwert als beweglichen Balken. Du übst Arduino & IoT Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Arduino & IoT Academy zu starten?
Keine Vorkenntnisse erforderlich. Arduino & IoT Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „Ein Balkendiagramm animieren“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Arduino & IoT Academy-Lektion Code schreiben und ausführen?
Ja. Jede Arduino & IoT Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Ein SSD1306-OLED anschließen und initialisieren
- Text in mehreren Größen zeichnen
- Linien, Rechtecke und Kreise
- Ein Balkendiagramm animieren