قلب على المصفوفة
القسم 10: الحساسات والشاشات بالكودالدرس 10.3 · ⏱ 8 دقائق
المصفوفة 8×8 فيها 64 مصباحًا. كل صفّ نكتبه رقمًا ثنائيًا: 1 مضيء و0 مطفأ. setRow يرسم صفًّا.
#include <LedControl.h>
LedControl lc = LedControl(12, 11, 10, 1);
byte heart[8] = {B00000000, B01100110, B11111111, B11111111, B11111111, B01111110, B00111100, B00011000};
void setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
}
void loop() {
for (int r = 0; r < 8; r++) {
lc.setRow(0, r, heart[r]);
}
}

🖥️ ماذا يحدث على المسرح؟
شغّلنا هذا الكود في روبو ميكر فنجح التحدي: «برافو! اشتغلت».
💡 نصيحة
ارسم القلب أولًا على ورقة مربّعات 8×8، ثم حوّل كل صف إلى 0 و 1.
📌 مثال آخر: وجه مبتسم
ثمانية صفوف، كل صف 8 نقاط: 1 = مضيئة، و 0 = مطفأة.
#include <LedControl.h>
LedControl lc = LedControl(12, 11, 10, 1);
byte img[8] = {B00111100, B01000010, B10100101, B10000001, B10100101, B10011001, B01000010, B00111100};
void setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
}
void loop() {
for (int r = 0; r < 8; r++) {
lc.setRow(0, r, img[r]);
}
}

✍️ طبّق بنفسك
ارسم قلبًا، ثم وجهًا مبتسمًا.
✍️ طبّق هنا في الدرس✖ أغلق المعملأو افتح المعمل في صفحة جديدة ↗
🎯 تحدَّ نفسك
سهل
سهم إلى أعلى.
👀 اعرض الحل🙈 أخفِ الحل
#include <LedControl.h>
LedControl lc = LedControl(12, 11, 10, 1);
byte img[8] = {B00011000, B00111100, B01111110, B11011011, B00011000, B00011000, B00011000, B00011000};
void setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
}
void loop() {
for (int r = 0; r < 8; r++) {
lc.setRow(0, r, img[r]);
}
}

النتيجة: سهم ⬆.
متوسط
مربّع (الإطار فقط).
👀 اعرض الحل🙈 أخفِ الحل
#include <LedControl.h>
LedControl lc = LedControl(12, 11, 10, 1);
byte img[8] = {B11111111, B10000001, B10000001, B10000001, B10000001, B10000001, B10000001, B11111111};
void setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
}
void loop() {
for (int r = 0; r < 8; r++) {
lc.setRow(0, r, img[r]);
}
}

النتيجة: إطار مربّع.
صعب
القلب ينبض: يظهر نصف ثانية ويختفي نصف ثانية.
👀 اعرض الحل🙈 أخفِ الحل
#include <LedControl.h>
LedControl lc = LedControl(12, 11, 10, 1);
byte img[8] = {B00000000, B01100110, B11111111, B11111111, B11111111, B01111110, B00111100, B00011000};
void setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
}
void loop() {
for (int r = 0; r < 8; r++) {
lc.setRow(0, r, img[r]);
}
delay(500);
lc.clearDisplay(0);
delay(500);
}

النتيجة: قلب يظهر ويختفي.

