İnternette hemen hemen hepimiz bir tablanın üstüne bir top bırakıldığında neresinden bırakılırsa bırakılsın motorları sayesinde hemen topu merkezine alıp dengede durmasını sağlayan top dengede tutan robot projelerine denk gelmişizdir. İzlemesi son derece keyifli ve kafamızda hep “ Acaba nasıl üretiliyor, ben de yapabilir miyim ki ? ” sorularını getiriyor. Sizin de kafanıza bu tarz sorular geliyorsa, gerçek toplar ve gerçek sistemler kadar olmasa da dijital top nasıl dengede tutabileceğinizi merak ediyor ve çevrenizi etkilemek istiyorsanız gelin projemizi yapmaya başlayalım.
Fotoğraftan da anlaşılabileceği gibi ne kadar basit bir sistem değil mi ? Proje bir adet eksen sensörü sayesinde hareketi algılayıp 8×8 Dot Matrix Display ekranında hareketin tam tersi yönde dijital top hareket etmesini sağlıyor. Bu sayede dijital top sanki dijital bir ekranda dengede kalmaya çalışıyor.
Ne Kullanmam Gerekiyor ki ?
Projemiz için ihtiyacımız olan tüm malzemelerin listesi ;
- Arduino Uno: https://www.robo90.com/arduino-uno-r3-smd-klonch340-cipli-usb-kablo-hediyeli
- Max7219 8×8 Dot Matrix Display Modülü – Kırmızı: https://www.robo90.com/max7219-8×8-dot-matrix-display-modulu-kirmizi
- MPU6050 6 Eksen İvme ve Gyro Sensörü: https://www.robo90.com/mpu6050-6-eksen-ivme-ve-gyro-sensoru-gy-521
- 40lı Ayrılabilen Dişi-Erkek Jumper Kablo: https://www.robo90.com/40li-ayrilabilen-disi-erkek-jumper-kablo-20cm-arduino-uyu
Donanım kısmı
Önce 8×8 Max7219 8×8 Dot Matrix Display Modülümüzü Arduino Uno ile bağlantılarını yaparak başlayalım. ( Fotoğraf 1.0 )
Göründüğü gibi 8×8 matrix modülümüzün sırasıyla VCC, GND, DIN, CS, CLK pinleri bulunmakta. Biz bu projemizde bu pinlerimizi Arduinonun şu pinlerine bağladık;
- VCC = Arduinonun +5V pini
- GND = Arduinonun GND pini
- DIN = Arduinonun 12. pini
- CS = Arduinonun 11. pini
- CLK = Arduinonun 10. pini
Bu bağlantıları yaptıktan sonra MPU6050 6 Eksen İvme ve Gyro Sensörünü nasıl bağlayacağımıza geçelim. ( Fotoğraf 1.1 )
Göründüğü gibi MPU6050 6 Eksen İvme ve Gyro Sensörünün sırasıyla VCC, GND, SCL, SDA, XDA, XCL, AD0 ve INT pinleri bulunmakta. Biz projemiz için ilk 4 pin olan VCC, GND, SCL ve SDA pinlerini kullanacağız. Bu pinleri sırasıyla Arduinonun şu pinlerine bağladık;
- VCC = Arduinonun +5V pini
- GND = Arduinonun GND pini
- SCL = Arduinonun A5 pinine
- SDA = Arduinonun A4 pinine
Gerekli olan tüm bağlantıları sırasıyla yaptıktan sonra şimdi projenin çalışma mantığına bakalım.
Peki Nasıl Çalışıyor ?
Yazımızın başlarında da bahsettiğimiz gibi aslında Proje bir adet eksen sensörü sayesinde hareketi algılayıp 8×8 Dot Matrix Display ekranında hareketin tam tersi yönde dijital top hareket etmesini sağlıyor. Bu sayede dijital top sanki dijital bir ekranda dengede kalmaya çalışıyormuş gibi görünüyor. Eksen sensörünün sadece X ve Y ekseni için ürettiği verileri kullanıyoruz. Sensörümüzü X ekseni için her bir hareketinde +-10, Y ekseni için de +-10 değerlerini üretecek şekilde ayarlıyoruz. ( İleride kaynak kodu incelerken bu kısıma değineceğiz ) ( Fotoğraf 1.2 )
Göründüğü gibi eksen sensörü her yönde hareket ettirdiğimizde eğime bağlı olarak konumu değişiyor. ( Fotoğraf 1.3 )
Şimdi ise 8×8 Dot Matrix’imizi aşağıdaki fotoğrafta göründüğü gibi dört parçaya bölelim. ( Fotoğraf 1.4 )
Daha sonra bu bölgelere sırasıyla 1, 2, 3, 4 diyelim. Hatırlarsanız eksen sensörü x ve y ekseni için +-10 arasında değerler üretiyordu. Bu yüzden ızgaranın eksenleri kestiği her bir noktayı sayısal parçalara ayırabiliriz ( -5, -2.5, -0, 2.5, 5 gibi ) Bu sayede her bir 64 farklı LED’in konumunu bulabiliriz. ( Fotoğraf 1.5 )
Yukarıdaki resme bakarak her bir LED’in konumunu ve bölgesini rahatlıkla söyleyebiliriz. Mesela 1. satır 2. sütundaki LED’in konumu için -7.5<x<-5 ve 7.5<y<10 , 2. bölgede diyebiliriz.
Hatırlarsanız eksen sensörümüz x ve y ekseni için +- 10 arasında değerler üretiyordu. Yani ben sensörüme doğru eğimi verirsem -7.5<x<-5 ve 7.5<y<10 arasında bir değeri tutturabilirim ve eğer bir if komutu yazıp -7.5<x<-5 ve 7.5<y<10 arasında 1. satır 2. sütundaki LED’ i aç dersem doğru eğimde 8×8 Dot Matrix modülünde o LED açılacaktır.
Peki ya eksen sensörü -7.5<x<-5 ve 7.5<y<10 arasındaki değerleri üretirken 1. satır 2. sütunun başlangıç noktası 0’ a göre aynalarsam ne olur ? Konum 8. satır ve 7. sütun olur. Peki o konumdaki LED’in yanmasını istersem ? İşte bu ! Benim eksen sensörümün tam tersi konumunda topumuz hareket ediyor. Asla düşürülemez dijital bir top !
Tabi ki de düşürebiliriz. Topumuzun ekrandan düşmemesi için bir çerçeve yaparsak eğer if-else sayımız 32’den 25’e düşer. Bu sayede 25 farklı ihtimali kodlarsak Ne olursa olsun düşüremeyeceğimiz bir dijital top yapmış oluruz. ( Fotoğraf 1.6 )
Projenin Yazılımı Nasıl Çalışır ?
Gerekli olan kütüphaneleri programımızın içine yazıyoruz.
#include "LedControl.h"
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Setup kısmında ise hem 8×8 Dot Matrix ekranı hem de MPU-6050 sensörü için gerekli olan kurulum kodlarını yazıyoruz.
void setup() {
Serial.begin(115200);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit MPU6050 test!");
// Try to initialize!
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
Serial.println("MPU6050 Found!");
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
Serial.print("Accelerometer range set to: ");
switch (mpu.getAccelerometerRange()) {
case MPU6050_RANGE_2_G:
Serial.println("+-2G");
break;
case MPU6050_RANGE_4_G:
Serial.println("+-4G");
break;
case MPU6050_RANGE_8_G:
Serial.println("+-8G");
break;
case MPU6050_RANGE_16_G:
Serial.println("+-16G");
break;
}
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
Serial.print("Gyro range set to: ");
switch (mpu.getGyroRange()) {
case MPU6050_RANGE_250_DEG:
Serial.println("+- 250 deg/s");
break;
case MPU6050_RANGE_500_DEG:
Serial.println("+- 500 deg/s");
break;
case MPU6050_RANGE_1000_DEG:
Serial.println("+- 1000 deg/s");
break;
case MPU6050_RANGE_2000_DEG:
Serial.println("+- 2000 deg/s");
break;
}
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.print("Filter bandwidth set to: ");
switch (mpu.getFilterBandwidth()) {
case MPU6050_BAND_260_HZ:
Serial.println("260 Hz");
break;
case MPU6050_BAND_184_HZ:
Serial.println("184 Hz");
break;
case MPU6050_BAND_94_HZ:
Serial.println("94 Hz");
break;
case MPU6050_BAND_44_HZ:
Serial.println("44 Hz");
break;
case MPU6050_BAND_21_HZ:
Serial.println("21 Hz");
break;
case MPU6050_BAND_10_HZ:
Serial.println("10 Hz");
break;
case MPU6050_BAND_5_HZ:
Serial.println("5 Hz");
break;
}
Serial.println("");
delay(100);
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
}
Sonrasında ekranda topun tüm konumlarının LCD için kütüphanesini yazıyoruz.
void middle() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000001,B10011001,B10011001,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
Bu sadece dijital top orta kısımda olduğu ve çevçevenin kodlandığı durum. ( Fotoğraf 1.7 )
Sonrasında ana void loop fonksiyonunda 25 farklı durum için 25 tane if kodluyoruz. Bu İf-Else yapılarının tamamını kodun tamamında bulabilirsiniz.
//y ekseni if-else
if ( a.acceleration.x<=2.5 && a.acceleration.x>=-2.5 && a.acceleration.y<=5 && a.acceleration.y>=2.5 ){
middletop1();
}
if ( a.acceleration.x<=2.5 && a.acceleration.x>=-2.5 && a.acceleration.y<=7.5 && a.acceleration.y>=5 ){
middletop2();
}
if ( a.acceleration.x<=2.5 && a.acceleration.x>=-2.5 && a.acceleration.y<=0 && a.acceleration.y>=-2.5 ){
middlebottom1();
}
if ( a.acceleration.x<=2.5 && a.acceleration.x>=-2.5 && a.acceleration.y<=-2.5 && a.acceleration.y>=-5 ){
middlebottom2();
}
//y ekseni if bitiş
Kodun tamamı ;
Kaynak Kod
//We always have to include the library
#include “LedControl.h”
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,10,11,1 );
/* we always wait a bit between updates of the display */
unsigned long delaytime=100;
void setup() {
Serial.begin(115200);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println(“Adafruit MPU6050 test!”);
// Try to initialize!
if (!mpu.begin()) {
Serial.println(“Failed to find MPU6050 chip”);
while (1) {
delay(10);
}
}
Serial.println(“MPU6050 Found!”);
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
Serial.print(“Accelerometer range set to: “);
switch (mpu.getAccelerometerRange()) {
case MPU6050_RANGE_2_G:
Serial.println(“+-2G”);
break;
case MPU6050_RANGE_4_G:
Serial.println(“+-4G”);
break;
case MPU6050_RANGE_8_G:
Serial.println(“+-8G”);
break;
case MPU6050_RANGE_16_G:
Serial.println(“+-16G”);
break;
}
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
Serial.print(“Gyro range set to: “);
switch (mpu.getGyroRange()) {
case MPU6050_RANGE_250_DEG:
Serial.println(“+- 250 deg/s”);
break;
case MPU6050_RANGE_500_DEG:
Serial.println(“+- 500 deg/s”);
break;
case MPU6050_RANGE_1000_DEG:
Serial.println(“+- 1000 deg/s”);
break;
case MPU6050_RANGE_2000_DEG:
Serial.println(“+- 2000 deg/s”);
break;
}
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.print(“Filter bandwidth set to: “);
switch (mpu.getFilterBandwidth()) {
case MPU6050_BAND_260_HZ:
Serial.println(“260 Hz”);
break;
case MPU6050_BAND_184_HZ:
Serial.println(“184 Hz”);
break;
case MPU6050_BAND_94_HZ:
Serial.println(“94 Hz”);
break;
case MPU6050_BAND_44_HZ:
Serial.println(“44 Hz”);
break;
case MPU6050_BAND_21_HZ:
Serial.println(“21 Hz”);
break;
case MPU6050_BAND_10_HZ:
Serial.println(“10 Hz”);
break;
case MPU6050_BAND_5_HZ:
Serial.println(“5 Hz”);
break;
}
Serial.println(“”);
delay(100);
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
}
/*
This method will display the characters for the
word “Arduino” one after the other on the matrix.
(you need at least 5×7 leds to see the whole chars)
*/
//y ekseni
void middle() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000001,B10011001,B10011001,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void middletop1() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10011001,B10011001,B10000001,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void middletop2() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10011001,B10011001,B10000001,B10000001,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void middlebottom1() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000001,B10000001,B10011001,B10011001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void middlebottom2() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000001,B10000001,B10000001,B10011001,B10011001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
//y ekseni bitiş
//x ekseni başlangıç
void middleright1() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000001,B10001101,B10001101,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void middleright2() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000001,B10000111,B10000111,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void middleleft1() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000001,B10110001,B10110001,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void middleleft2() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000001,B11100001,B11100001,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
//x ekseni bitiş
//1. alan
void area1topright1() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10001101,B10001101,B10000001,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void area1topright2() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10001101,B10001101,B10000001,B10000001,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void area1topright4() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000111,B10000111,B10000001,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void area1topright5() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000111,B10000111,B10000001,B10000001,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void area1topright7() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000111,B10000111,B10000001,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void area1topright8() {
/* here is the data for the characters */
byte ball[8]={B11111111,B01000111,B10000111,B10000001,B10000001,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
//1. alan bitiş
//2. alan
void area2left1() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10110001,B10110001,B10000001,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void area2left2() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10110001,B10110001,B10000001,B10000001,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void area2left4() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B11100001,B11100001,B10000001,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void area2left5() {
/* here is the data for the characters */
byte ball[8]={B11111111,B11100001,B11100001,B10000001,B10000001,B10000001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
//2. alan bitiş
//3. alan
void area3left1() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000001,B10000001,B10110001,B10110001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void area3left2() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000001,B10000001,B10000001,B10110001,B10110001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void area3left4() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000001,B10000001,B11100001,B11100001,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void area3left5() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000001,B10000001,B10000001,B11100001,B11100001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
//3. alan bitiş
//4. alan
void area4right1() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000001,B10000001,B10001101,B10001101,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void area4right2() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000001,B10000001,B10000001,B10001101,B10001101,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void area4right4() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000001,B10000001,B10000111,B10000111,B10000001,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void area4right5() {
/* here is the data for the characters */
byte ball[8]={B11111111,B10000001,B10000001,B10000001,B10000001,B10000111,B10000111,B11111111};
/* now display them one by one with a small delay */
lc.setRow(0,0,ball[0]);
lc.setRow(0,1,ball[1]);
lc.setRow(0,2,ball[2]);
lc.setRow(0,3,ball[3]);
lc.setRow(0,4,ball[4]);
lc.setRow(0,5,ball[5]);
lc.setRow(0,6,ball[6]);
lc.setRow(0,7,ball[7]);
lc.setRow(0,8,ball[8]);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
lc.setRow(0,5,0);
lc.setRow(0,6,0);
lc.setRow(0,7,0);
lc.setRow(0,8,0);
}
void loop() {
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
if ( a.acceleration.x<2.5 && a.acceleration.x>0 && a.acceleration.y<2.5 && a.acceleration.y>0 ){
middle();
}
//y ekseni if-else
if ( a.acceleration.x<2.5 && a.acceleration.x>-2.5 && a.acceleration.y<5 && a.acceleration.y>2.5 ){
middletop1();
}
if ( a.acceleration.x<2.5 && a.acceleration.x>-2.5 && a.acceleration.y<7.5 && a.acceleration.y>5 ){
middletop2();
}
if ( a.acceleration.x<2.5 && a.acceleration.x>-2.5 && a.acceleration.y<0 && a.acceleration.y>-2.5 ){
middlebottom1();
}
if ( a.acceleration.x<2.5 && a.acceleration.x>-2.5 && a.acceleration.y<-2.5 && a.acceleration.y>-5 ){
middlebottom2();
}
//y ekseni if bitiş
//x ekseni if
if ( a.acceleration.x<5 && a.acceleration.x>2.5 && a.acceleration.y<2.5 && a.acceleration.y>-2.5 ){
middleright1();
}
if ( a.acceleration.x<7.5 && a.acceleration.x>5 && a.acceleration.y<2.5 && a.acceleration.y>-2.5 ){
middleright2();
}
if ( a.acceleration.x<-2.5 && a.acceleration.x>-5 && a.acceleration.y<2.5 && a.acceleration.y>-2.5 ){
middleleft1();
}
if ( a.acceleration.x<-5 && a.acceleration.x>-7.5 && a.acceleration.y<2.5 && a.acceleration.y>-2.5 ){
middleleft2();
}
//x ekseni if bitiş
//1. alan if
if ( a.acceleration.x<5 && a.acceleration.x>2.5 && a.acceleration.y<5 && a.acceleration.y>2.5 ){
area1topright1();
}
if ( a.acceleration.x<5 && a.acceleration.x>2.5 && a.acceleration.y<7.5 && a.acceleration.y>5 ){
area1topright2();
}
if ( a.acceleration.x<7.5 && a.acceleration.x>5 && a.acceleration.y<5 && a.acceleration.y>2.5 )
{
area1topright4();
}
if ( a.acceleration.x<7.5 && a.acceleration.x>5 && a.acceleration.y<7.5 && a.acceleration.y>5 ){
area1topright5();
}
//1. alan bitti
//2. alan
if ( a.acceleration.x<-2.5 && a.acceleration.x>-5 && a.acceleration.y<5 && a.acceleration.y>2.5 ){
area2left1();
}
if ( a.acceleration.x<-2.5 && a.acceleration.x>-5 && a.acceleration.y<10 && a.acceleration.y>5 ){
area2left2();
}
if ( a.acceleration.x<-5 && a.acceleration.x>-10 && a.acceleration.y<5 && a.acceleration.y>2.5 ){
area2left4();
}
if ( a.acceleration.x<-5 && a.acceleration.x>-10 && a.acceleration.y<10 && a.acceleration.y>5 ){
area2left5();
}
//2. alan bitti
//3. alan
if ( a.acceleration.x<-2.5 && a.acceleration.x>-5 && a.acceleration.y<-2.5 && a.acceleration.y>-5 ){
area3left1();
}
if ( a.acceleration.x<-2.5 && a.acceleration.x>-5 && a.acceleration.y<-5 && a.acceleration.y>=-10 ){
area3left2();
}
if ( a.acceleration.x<-5 && a.acceleration.x>-10 && a.acceleration.y<-2.5 && a.acceleration.y>-5 ){
area3left4();
}
if ( a.acceleration.x<-5 && a.acceleration.x>-10 && a.acceleration.y<-5 && a.acceleration.y>-10 ){
area3left5();
}
//3. alan bitti
//4. alan
if ( a.acceleration.x<5 && a.acceleration.x>2.5 && a.acceleration.y<-2.5 && a.acceleration.y>-5 ){
area4right1();
}
if ( a.acceleration.x<5 && a.acceleration.x>2.5 && a.acceleration.y<-5 && a.acceleration.y>-10 ){
area4right2();
}
if ( a.acceleration.x<10 && a.acceleration.x>5 && a.acceleration.y<-2.5 && a.acceleration.y>=-5 ){
area4right4();
}
if ( a.acceleration.x<10 && a.acceleration.x>5 && a.acceleration.y<-5 && a.acceleration.y>-10 ){
area4right5();
}
}
Bu projemizde de çevrenize gösterdiğiniz zaman gülümsetecek, insanların şaşıracağı, çözümlerinin de anlaşılmasının da oldukça basit olduğu dengede duramayan dijital top projesini inceledik. Bu tarz çevrenizi şaşırtacak veya bakış açınızı genişletecek başka projeler arıyorsanız aşağıdaki projelerimi inceleyebilirsiniz.
Yazının başındaki fotoğraf https://www.youtube.com/watch?v=tPr6-Rh0m-8 videosundan alınmıştır