#include <SPI.h>
const int DIN_PIN = 51; // Pin SPI MOSI (Data In)
const int CS_PIN = 53; // Pin Chip Select
const int CLK_PIN = 52; // Pin SPI Clock
const int TombolA = 2;
const int TombolB = 3;
int count = 0; // Variabel untuk menghitung
byte numbers[][8] = {
{ B00011100, B00100010, B00100010, B00100010, B00100010, B00100010, B00011100 }, // 0
{ B00001000, B00001100, B00001000, B00001000, B00001000, B00001000, B00011100 }, // 1
{ B00111000, B01001000, B01000000, B00100000, B00010000, B00001000, B01111000 }, // 2
{ B00111000, B01001000, B01000000, B01100000, B01000000, B01000000, B00111000 }, // 3
{ B00001000, B00011000, B00010100, B00010010, B00011110, B00010000, B00010000 }, // 4
{ B01111000, B00001000, B00001000, B00111000, B01000000, B01001000, B00110000 }, // 5
{ B00110000, B01001000, B00001000, B00111000, B01001000, B01001000, B00110000 }, // 6
{ B01111000, B01000000, B00100000, B00010000, B00001000, B00001000, B00001000 }, // 7
{ B00110000, B01001000, B01001000, B00110000, B01001000, B01001000, B00110000 }, // 8
{ B00110000, B01001000, B01001000, B01110000, B01000000, B01000000, B00110000 } // 9
};
void setup() {
pinMode(DIN_PIN, OUTPUT);
pinMode(CS_PIN, OUTPUT);
pinMode(CLK_PIN, OUTPUT);
pinMode(TombolA, INPUT_PULLUP); // Tombol A sebagai input pull-up
pinMode(TombolB, INPUT_PULLUP); // Tombol B sebagai input pull-up
SPI.begin();
}
void loop() {
int statusTombolA = digitalRead(TombolA);
int statusTombolB = digitalRead(TombolB);
if (statusTombolA == LOW) { // Tombol A ditekan
displayNumber(count);
delay(200);
count++;
if (count > 9) {
count = 0;
}
}
if (statusTombolB == LOW) { // Tombol B ditekan
displayNumber(count);
delay(200);
count--;
if (count < 0) {
count = 9; // Kembali ke 9 jika count kurang dari 0
}
}
}
void sendCommand(byte address, byte data) {
// Send a command to the MAX7219
digitalWrite(CS_PIN, LOW);
SPI.transfer(address);
SPI.transfer(data);
digitalWrite(CS_PIN, HIGH);
}
void displayNumber(int num) {
if (num >= 0 && num <= 9) {
for (int digit = 1; digit <= 8; digit++) {
sendCommand(digit, numbers[num][digit - 1]);
}
}
}FPS: 0
Power: 0.00W
Power: 0.00W