0Pricing
Arduino & IoT Academy · Урок

Анимация столбчатой диаграммы

Показывайте меняющиеся показания датчика движущимся столбцом.

«Анимация столбчатой диаграммы» — бесплатный урок Arduino & IoT Academy на CoddyKit. Это урок 4 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Arduino & IoT Academy, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Arduino & IoT Academy содержит 4 уроков всего.

Части этого урока еще не переведены и отображаются на английском.

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.

Часто задаваемые вопросы

Урок «Анимация столбчатой диаграммы» бесплатный?

Да — полный текст урока «Анимация столбчатой диаграммы» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Arduino & IoT Academy, подпишись на CoddyKit PRO. Курс Arduino & IoT Academy содержит 4 уроков всего.

Чему я научусь в уроке «Анимация столбчатой диаграммы»?

Показывайте меняющиеся показания датчика движущимся столбцом. Ты практикуешь Arduino & IoT Academy с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать Arduino & IoT Academy?

Предыдущий опыт не требуется. Arduino & IoT Academy на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 4 из 4.

Сколько времени занимает урок «Анимация столбчатой диаграммы»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке Arduino & IoT Academy?

Да. Каждый урок Arduino & IoT Academy включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Подключение и инициализация OLED SSD1306
  2. Вывод текста в нескольких размерах
  3. Линии, прямоугольники и окружности
  4. Анимация столбчатой диаграммы
← Назад к Arduino & IoT Academy