Senin, 26 Januari 2026

Dot Matri Untuk Lampu Belakang Trainer Motor Listrik

Contoh Program

Kabel Biru = Rem

Kabel Kuning = Sein Kanan

Kabel Hijau Sein Kiri


 //  8x8 board besar dengan fungsi tombol pasang di pin 10 dan 11 external pull up ke 5V

// Menampilkan NAMA OTOTRONIK
// Fill in the pins you used on your own setup.

#define ROW_1 8
#define ROW_2 9
#define ROW_3 A1
#define ROW_4 5
#define ROW_5 12
#define ROW_6 A2
#define ROW_7 13
#define ROW_8 A0

#define COL_1 4
#define COL_2 A5
#define COL_3 A4
#define COL_4 7
#define COL_5 A3
#define COL_6 6
#define COL_7 3
#define COL_8 2

const int TombolKiri = 10;
const int TombolKanan = 11;
int Kiri = 1;  // variable for reading the pushbutton status
int Kanan = 1;  // variable for reading the pushbutton status
const byte rows[] = {
    ROW_1, ROW_2, ROW_3, ROW_4, ROW_5, ROW_6, ROW_7, ROW_8
};


// nama siswa Muncul saat kunci kontak ON
byte nama1[] = {0x00,0x00,0x00,0x3c, 0x42,0x42,0x3c,0x00};
byte nama2[] = {0x00,0x00,0x02,0x02,0x7e,0x02,0x02,0x00};
byte nama3[] = {0x00,0x00,0x00,0x3c,0x42,0x42,0x3c,0x00};
byte nama4[] = {0x00, 0x00,0x02,0x02,0x7e,0x02,0x02,0x00};
byte nama5[] = {0x00,0x7e,0x1a,0x2a, 0x4e,0x00,0x00, 0x00};
byte nama6[] = {0x00,0x00,0x00,0x3c,0x42, 0x42,0x3c,0x00};
byte nama7[] = {0x00,0x7e,0x20,0x10, 0x08,0x04,0x7e,0x00};
byte nama8[] = {0x00,0x00,0x00, 0x00,0x7e,0x00,0x00,0x00};
byte nama9[] = {0x00,0x7e,0x08,0x14,0x62,0x00,0x00,0x00};
byte nama10[] = {0x00, 0xFF, 0x38, 0x44, 0x83, 0x00, 0xFF, 0x08};
byte nama11[] = {0xFF, 0x38, 0x44, 0x83, 0x00, 0xFF, 0x08, 0x08};
byte nama12[] = {0x38, 0x44, 0x83, 0x00, 0xFF, 0x08, 0x08, 0xFF};
byte nama13[] = {0x44, 0x83, 0x00, 0xFF, 0x08, 0x08, 0xFF, 0x00};
byte nama14[] = {0x83, 0x00, 0xFF, 0x08, 0x08, 0xFF, 0x00, 0xF9};
byte nama15[] = {0x00, 0xFF, 0x08, 0x08, 0xFF, 0x00, 0xF9, 0x89};
byte nama16[] = {0xFF, 0x08, 0x08, 0xFF, 0x00, 0xF9, 0x89, 0x8F};
byte nama17[] = {0x08, 0x08, 0xFF, 0x00, 0xF9, 0x89, 0x8F, 0x00};
byte nama18[] = {0x08, 0xFF, 0x00, 0xF9, 0x89, 0x8F, 0x00, 0xFF};
byte nama19[] = {0xFF, 0x00, 0xF9, 0x89, 0x8F, 0x00, 0xFF, 0x88};
byte nama20[] = {0x00, 0xF9, 0x89, 0x8F, 0x00, 0xFF, 0x88, 0xFF};
byte nama21[] = {0xF9, 0x89, 0x8F, 0x00, 0xFF, 0x88, 0xFF, 0x00};
byte nama22[] = {0x89, 0x8F, 0x00, 0xFF, 0x88, 0xFF, 0x00, 0xFF};
byte nama23[] = {0x8F, 0x00, 0xFF, 0x88, 0xFF, 0x00, 0xFF, 0x10};
byte nama24[] = {0x00, 0xFF, 0x88, 0xFF, 0x00, 0xFF, 0x10, 0x08};
byte nama25[] = {0xFF, 0x88, 0xFF, 0x00, 0xFF, 0x10, 0x08, 0x04};
byte nama26[] = {0x88, 0xFF, 0x00, 0xFF, 0x10, 0x08, 0x04, 0xFF};
byte nama27[] = {0xFF, 0x00, 0xFF, 0x10, 0x08, 0x04, 0xFF, 0x00};
byte nama28[] = {0x00, 0xFF, 0x10, 0x08, 0x04, 0xFF, 0x00, 0x00};
byte nama29[] = {0xFF, 0x10, 0x08, 0x04, 0xFF, 0x00, 0x00, 0x00};
byte nama30[] = {0x10, 0x08, 0x04, 0xFF, 0x00, 0x00, 0x00, 0x00};
byte nama31[] = {0x08, 0x04, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00};
byte nama32[] = {0x04, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
byte nama33[] = {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
byte nama34[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

//rem
byte rem1 []={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte rem2 []={0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00};
byte rem3 []={0x00, 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x00};
byte rem4 []={0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00};
byte rem5 []={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};

//seinR
byte seinR1 []={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte seinR2 []={0x18, 0x30, 0x60, 0xff, 0xff, 0x60, 0x30, 0x18};
//Sein L
byte seinL1 []={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte seinL2 []={0x18, 0x0c, 0x06, 0xff, 0xff, 0x06, 0x0c, 0x18};

float timeCount = 0;

void setup() {
    // Open serial port
    Serial.begin(9600);
   
    // Set all used pins to OUTPUT
    // This is very important! If the pins are set to input
    for (byte i = 2; i <= 9; i++)
        pinMode(i, OUTPUT);
    pinMode(A0, OUTPUT);
    pinMode(A1, OUTPUT);
    pinMode(A2, OUTPUT);
    pinMode(A3, OUTPUT);
    pinMode(A4, OUTPUT);
    pinMode(A5, OUTPUT);
    pinMode(13, OUTPUT);
    pinMode(12, OUTPUT);
    pinMode(TombolKiri, INPUT);
    pinMode(TombolKanan, INPUT);
}

void loop() {
// untuk mendeklarasikan tombol
Kiri = digitalRead(TombolKiri);
Kanan = digitalRead(TombolKanan);

if (Kanan == HIGH && Kiri == LOW) {
  // This could be rewritten to not use a delay, which would make it appear brighter
delay(5);
timeCount += 1;
if(timeCount <  20) {
drawScreen(seinL1);
} else if (timeCount < 40) {
drawScreen(seinL2);
} else {
// back to the start
timeCount = 0;
}}
if (Kanan == LOW && Kiri == HIGH) {
  // This could be rewritten to not use a delay, which would make it appear brighter
delay(5);
timeCount += 1;
if(timeCount <  20) {
drawScreen(seinR1);
} else if (timeCount < 40) {
drawScreen(seinR2);
} else {
// back to the start
timeCount = 0;
}}
if (Kanan == LOW && Kiri == LOW) {
  // This could be rewritten to not use a delay, which would make it appear brighter
delay(5);
timeCount += 2;
if(timeCount <  20) {
drawScreen(rem1);
} else if (timeCount < 40) {
drawScreen(rem2);
} else if (timeCount < 60) {
drawScreen(rem3);
} else if (timeCount < 80) {
drawScreen(rem4);
} else if (timeCount < 100) {
drawScreen(rem5);
}
else {
// back to the start
timeCount = 0;
}}
if (Kanan == HIGH && Kiri == HIGH) {
    delay(5);
timeCount += 1;
if(timeCount <  20) {
drawScreen(nama1);
} else if (timeCount < 40) {
drawScreen(nama2);
} else if (timeCount < 60) {
drawScreen(nama3);
} else if (timeCount < 80) {
drawScreen(nama4);
} else if (timeCount < 100){
drawScreen(nama5);
} else if (timeCount < 120){
drawScreen(nama6);
} else if (timeCount < 140){
drawScreen(nama7);
} else if (timeCount < 160){
drawScreen(nama8);
} else if (timeCount < 180){
drawScreen(nama9);
} else if (timeCount < 200){
drawScreen(nama10);
} else if (timeCount < 220){
drawScreen(nama11);
} else if (timeCount < 240){
drawScreen(nama12);
} else if (timeCount < 260){
drawScreen(nama13);
} else if (timeCount < 280){
drawScreen(nama14);
} else if (timeCount < 300){
drawScreen(nama15);
} else if (timeCount < 320){
drawScreen(nama16);
} else if (timeCount < 340){
drawScreen(nama17);
} else if (timeCount < 360){
drawScreen(nama18);
} else if (timeCount < 380){
drawScreen(nama19);
} else if (timeCount < 400){
drawScreen(nama20);
} else if (timeCount < 420){
drawScreen(nama21);
} else if (timeCount < 440){
drawScreen(nama22);
} else if (timeCount < 460){
drawScreen(nama23);
} else if (timeCount < 480){
drawScreen(nama24);
} else if (timeCount < 500){
drawScreen(nama25);
} else if (timeCount < 520){
drawScreen(nama26);
} else if (timeCount < 540){
drawScreen(nama27);
} else if (timeCount < 560){
drawScreen(nama28);
} else if (timeCount < 580){
drawScreen(nama29);
} else if (timeCount < 600){
drawScreen(nama30);
} else if (timeCount < 620){
drawScreen(nama31);
} else if (timeCount < 640){
drawScreen(nama32);
} else if (timeCount < 660){
drawScreen(nama33);
} else if (timeCount < 680){
drawScreen(nama34);

} else {
// back to the start nama
timeCount = 0;
}
  }
}
 void  drawScreen(byte buffer2[]){
   // Turn on each row in series
    for (byte i = 0; i < 8; i++) {
        setColumns(buffer2[i]); // Set columns for this specific row
       
        digitalWrite(rows[i], HIGH);
        delay(2); // Set this to 50 or 100 if you want to see the multiplexing effect!
        digitalWrite(rows[i], LOW);
    }
}

void setColumns(byte b) {
    digitalWrite(COL_1, (~b >> 0) & 0x01); // Get the 1st bit: 10000000
    digitalWrite(COL_2, (~b >> 1) & 0x01); // Get the 2nd bit: 01000000
    digitalWrite(COL_3, (~b >> 2) & 0x01); // Get the 3rd bit: 00100000
    digitalWrite(COL_4, (~b >> 3) & 0x01); // Get the 4th bit: 00010000
    digitalWrite(COL_5, (~b >> 4) & 0x01); // Get the 5th bit: 00001000
    digitalWrite(COL_6, (~b >> 5) & 0x01); // Get the 6th bit: 00000100
    digitalWrite(COL_7, (~b >> 6) & 0x01); // Get the 7th bit: 00000010
    digitalWrite(COL_8, (~b >> 7) & 0x01); // Get the 8th bit: 00000001
   
    // If the polarity of your matrix is the opposite of mine
    // remove all the '~' above.
}

Tidak ada komentar:

Posting Komentar