تحريك مخطط أعمدة
مثّل مستشعرًا متغيرًا في صورة شريط متحرك.
تحريك مخطط أعمدة درس مجاني في 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 يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.