بسم الله الرحمن الرحيم
اولا الأدوات
Arduino uno
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhF-l4gk0rv3Ps1m3QMh_h2w6uKbRMy6jOrFCmX11kODVvZ-hhyphenhyphenigxDvFwuIYSiwI6EdujNqTEl4ETF9MUwBoHgIcxeRDYWJBCTVX-aAhSjP1VVeupQ2YvMa8CIBU4BKYagPhAF36365x8/s16000/2.jpg)
oled 128x64
الشاشة التى سنستخدمها فى عرض الحركات عليهاثانيا التوصيلات :
ثالثا الكود :
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
while (!Serial);
Serial.println("\nI2C Scanner");
}
void loop() {
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for (address = 1; address < 127; address++ ) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address < 16)
Serial.print("0");
Serial.print(address, HEX);
Serial.println(" !");
nDevices++;
}
else if (error == 4) {
Serial.print("Unknown error at address 0x");
if (address < 16)
Serial.print("0");
Serial.println(address, HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000);
}
فهذا الكود فى الأعلى يقوم الأردوينو بقراءة كل العناوين المتاحة للوصول الى العنوان الموجود عليه الشاشة
كل ما عليك الذهاب الى serial monitor لتجد عنوان الشاشة التى تعمل عليها
ثم ننتقل الى كود المشروع
#include <Adafruit_SSD1306.h>
#define OLED_ADDR 0xZZ
Adafruit_SSD1306 display(-1);
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
display.clearDisplay();
display.display();
delay(10000);
}
void loop() {
happy(); delay (random (500, 1000));
cierra();delay (150);
enfado();delay (random (1000, 3000));
cierra();delay (150);
entorna();delay (random (1000, 3000));
cierra();delay (150);
enfado1(); delay (random (1000, 3000));
cierra();delay (150);
triste();delay (random (1000, 3000));
cierra();delay (150);
abre();delay (random (500, 3000));
cierra(); delay (150);
happy();delay (random (500, 1000));
}
void abre() {
display.clearDisplay();
display.fillCircle (50, 15, 12, WHITE); //ojo izquierdo grande
display.fillCircle (82, 20, 7, WHITE); //ojo derecho pequeño
display.display();
}
void cierra() {
display.clearDisplay();
display.drawFastHLine(40, 15, 20, WHITE);
display.drawFastHLine(72, 20, 15, WHITE);
display.display();
}
void entorna() {
display.clearDisplay();
display.fillCircle (42, 10, 20, WHITE); //ojo izquierdo grande
display.fillCircle (82, 10, 15, WHITE); //ojo derecho pequeño
display.fillRect (0, 0, 128, 15, BLACK); //ceja superior
display.fillRect (0, 40, 128, 15, BLACK); //ceja inferior
display.display();
}
void triste() {
display.clearDisplay();
display.fillCircle (42, 10, 17, WHITE); //ojo izquierdo grande
display.fillCircle (82, 10, 17, WHITE); //ojo derecho pequeño
display.fillTriangle (0, 0, 0, 35, 78, 0, BLACK); //ceja superior
display.fillTriangle (50, 0, 128, 35, 128, 0, BLACK); //ceja superior
display.display();
}
void happy() {
display.clearDisplay();
display.fillCircle (42, 25, 15, WHITE); //ojo izquierdo grande
display.fillCircle (82, 25, 15, WHITE); //ojo derecho pequeño
display.fillCircle (42, 33, 20, BLACK); //ojo izquierdo grande
display.fillCircle (82, 33, 20, BLACK); //ojo derecho pequeño
display.display();
}
void enfado() {
display.clearDisplay();
display.fillCircle (42, 10, 18, WHITE); //ojo izquierdo grande
display.fillCircle (82, 10, 12, WHITE); //ojo derecho pequeño
display.fillTriangle (0, 0, 54, 26, 118, 0, BLACK); //ceja superior
display.display();
}
void enfado1() {
display.clearDisplay();
display.fillCircle (42, 10, 18, WHITE); //ojo izquierdo grande
display.fillCircle (82, 10, 12, WHITE); //ojo derecho pequeño
display.fillTriangle (0, 0, 65, 15, 120, 0, BLACK); //ceja superior
display.display();
}
في البداية يجب تعريف المكتبة الأساسية للتعامل مع شاشة oled
#include <Adafruit_SSD1306.h>
يتم استبدال zz بالعنوان الذي حصلنا عليه من الكود السابق
ثم نقوم بتيئة الشاشة للعمل والبدء فى العرض
display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
display.clearDisplay();
display.display();
ثم نقوم بتعريف دالة لكل شكل من الأشكال التى يرسمها روبوت كوزمو على شاشته وعمل استدعاء لكل هذه الدالات
في نهاية المشروع يعد هذا بداية ليس ترقبونا
لتحميل الأكود اضغط هنا
تصميم وبرمجة : بلال حسان سعدي