0% found this document useful (0 votes)
29 views5 pages

Counter Dot

The document defines arrays to represent the digits 0-9 for a 7-segment display. It also defines pin mappings for the rows and columns of a dot matrix display. The code increments a variable over time and uses the arrays to display the digits on the dot matrix by activating the appropriate row and column pins.

Uploaded by

Zulkarnain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views5 pages

Counter Dot

The document defines arrays to represent the digits 0-9 for a 7-segment display. It also defines pin mappings for the rows and columns of a dot matrix display. The code increments a variable over time and uses the arrays to display the digits on the dot matrix by activating the appropriate row and column pins.

Uploaded by

Zulkarnain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

byte nol[] = { 0b00000111, 0b00000101, 0b00000101, 0b00000101, 0b00000101, 0b00000101, 0b00000111, 0b00000000 };

byte satu[] = { 0b00000010, 0b00000110, 0b00000010, 0b00000010, 0b00000010, 0b00000010, 0b00000111, 0b00000000 };

byte dua[] = { 0b00000111, 0b00000001, 0b00000001, 0b00000111, 0b00000100, 0b00000100, 0b00000111, 0b00000000 };

byte tiga[] = { 0b00000111, 0b00000001, 0b00000001, 0b00000111, 0b00000001, 0b00000001, 0b00000111, 0b00000000 };

byte empat[] = { 0b00000101, 0b00000101, 0b00000101, 0b00000111, 0b00000001, 0b00000001, 0b00000001,


0b00000000 };

byte lima[] = { 0b00000111, 0b00000100, 0b00000100, 0b00000111, 0b00000001, 0b00000001, 0b00000111, 0b00000000 };

byte enam[] = { 0b00000111, 0b00000100, 0b00000100, 0b00000111, 0b00000101, 0b00000101, 0b00000111,


0b00000000 };

byte tujuh[] = { 0b00000111, 0b00000001, 0b00000001, 0b00000001, 0b00000001, 0b00000001, 0b00000001,


0b00000000 };

byte delapan[] = { 0b00000111, 0b00000101, 0b00000101, 0b00000111, 0b00000101, 0b00000101, 0b00000111,


0b00000000 };

byte sembilan[] = { 0b0111, 0b0101, 0b0101, 0b0111, 0b0001, 0b0001, 0b0111, 0b0000 };

// deklarasi array posisi pin dot matrix disesuaikan dengan pin Arduino (nilai -1 adalah dummy agar array dimulai dari angka 1)

int pins[17] = { -1, A0, A1, A2, A3, 10, 11, 12, 13, 9, 8, 7, 6, 5, 4, 3, 2};

// deklarasi array kolom disesuaikan dengan posisi pin dot matrix

int cols[8] = {6, 7, 8, 9, 10, 11, 12, 13};

// deklarasi array baris disesuaikan dengan posisi pin dot matrix

int rows[8] = {A0, A1, A2, A3, 2, 3, 4, 5};

unsigned long previousMillis = 0;

byte angkaPuluhan, angkaSatuan;

int angka = 19;

int Speed = 1000; // 1 detik (1000 mili second)

void setup()

// set pin sebagai output 


for (int i = 1; i <= 16; i++)

pinMode(pins[i], OUTPUT);

// set kolom menghasilkan output LOW

for (int i = 1; i <= 8; i++)

digitalWrite(cols[i - 1], HIGH);

// set baris menghasilkan output LOW

for (int i = 1; i <= 8; i++)

digitalWrite(rows[i - 1], HIGH);

void loop()

unsigned long currentMillis = millis();

if (currentMillis - previousMillis >= Speed) {

previousMillis = currentMillis;

angka++; // incr variable angka

// angka--; // decr variable angka

PrintToMatrix();

}
void PrintToMatrix()

angkaPuluhan = angka / 10;

angkaSatuan = angka % 10;

for (byte n = 0; n < 8; n++)

for (byte i = 0; i < 4; i++)

byte Bit = map(i, 0, 3, 3, 0);

PrintCols(i, n, Bit, angkaPuluhan);

PrintCols(i+4, n, Bit, angkaSatuan);

digitalWrite(rows[n], LOW);

delayMicroseconds(100);

digitalWrite(rows[n], HIGH);

void PrintCols(byte i, byte n, byte Bit, byte number)

switch (number) {

case 0:

digitalWrite(cols[i], ((nol[n] >> Bit) & 0x01));

break;

case 1:

digitalWrite(cols[i], ((satu[n] >> Bit) & 0x01));

break;

case 2:
digitalWrite(cols[i], ((dua[n] >> Bit) & 0x01));

break;

case 3:

digitalWrite(cols[i], ((tiga[n] >> Bit) & 0x01));

break;

case 4:

digitalWrite(cols[i], ((empat[n] >> Bit) & 0x01));

break;

case 5:

digitalWrite(cols[i], ((lima[n] >> Bit) & 0x01));

break;

case 6:

digitalWrite(cols[i], ((enam[n] >> Bit) & 0x01));

break;

case 7:

digitalWrite(cols[i], ((tujuh[n] >> Bit) & 0x01));

break;

case 8:

digitalWrite(cols[i], ((delapan[n] >> Bit) & 0x01));

break;

case 9:

digitalWrite(cols[i], ((sembilan[n] >> Bit) & 0x01));

break;

}
}

You might also like