#include <SPI.h>
#include <DMD2.h>
#include "fonts/Arial_Black_16.h"
#include <fonts/MyBigFont.h>
#include <EEPROM.h>
// Mendifinisikan fungsi
#define bCLEAR A1
#define bRIGHT A2
#define bLEFT A0
#define Panjang 3 // Jumlah panjang Display P10
#define Lebar 2 // Jumlah lebar Display P10
SoftDMD dmd(Panjang, Lebar);
// Deklarasi Variable
byte Brightness;
byte debounce = 100;
int rightScore = 0;
int leftScore = 0;
int i;
char dmdBuff[10];
char BT;
// Fungsi Setup, dikerjakan sekali saat arduino reset
void setup() {
Brightness = EEPROM.read(0);
dmd.setBrightness(10);
dmd.selectFont(Arial_Black_16);
dmd.begin();
dmd.clearScreen();
Serial.begin(9600);
pinMode(bCLEAR,INPUT_PULLUP);
pinMode(bRIGHT,INPUT_PULLUP);
pinMode(bLEFT,INPUT_PULLUP);
blinkDisplay();
}
// Fungsi Blink Display, berfungsi untuk membuat display kedap-kedip
void blinkDisplay(){
dmd.clearScreen();
delay(300);
sprintf(dmdBuff,"%d",leftScore);
dmd.selectFont(Arial_Black_16);
dmd.drawString( 13, 8, dmdBuff );
dmd.selectFont(Arial_Black_16);
dmd.drawString( 29, 8, "-" );
sprintf(dmdBuff,"%2d",rightScore);
dmd.selectFont(Arial_Black_16);
dmd.drawString( 40, 8, dmdBuff );
delay(300);
dmd.clearScreen();
delay(300);
sprintf(dmdBuff,"%d",leftScore);
dmd.selectFont(Arial_Black_16);
dmd.drawString( 13, 8, dmdBuff );
dmd.selectFont(Arial_Black_16);
dmd.drawString( 29, 8, "-");
sprintf(dmdBuff,"%2d",rightScore);
dmd.selectFont(Arial_Black_16);
dmd.drawString( 40, 8, dmdBuff);
delay(300);
dmd.clearScreen();
delay(300);
}
//Fungsi GOAL, menampilkan text GOAL saat input dimasukan
void GOAL(){
dmd.clearScreen();
delay(400);
dmd.selectFont(MyBigFont);
dmd.drawString(5, 0, "GOAL!!!" );
delay(400);
dmd.selectFont(MyBigFont);
dmd.clearScreen();
delay(400);
dmd.selectFont(MyBigFont);
dmd.drawString(5, 0, "GOAL!!!" );
delay(3000);
}
// Fungsi Loop, dikerjakan berulang-ulang
void loop() {
if(Serial.available()){
BT = Serial.read();
}
if(digitalRead(bCLEAR) == LOW || BT == 'X') {
delay(debounce);
leftScore = 0;
rightScore = 0;
dmd.clearScreen();
BT = 0;
}
if(digitalRead(bLEFT) == LOW || BT == 'A') {
delay(debounce);
leftScore++;
GOAL();
blinkDisplay();
BT = 0;
}
if(digitalRead(bRIGHT) == LOW || BT == 'B') {
delay(debounce);
rightScore++;
GOAL();
blinkDisplay();
BT = 0;
}
sprintf(dmdBuff,"%d",leftScore);
dmd.selectFont(Arial_Black_16);
dmd.drawString( 13, 8, dmdBuff );
dmd.selectFont(Arial_Black_16);
dmd.drawString( 29, 8, "-" );
sprintf(dmdBuff,"%2d",rightScore);
dmd.selectFont(Arial_Black_16);
dmd.drawString( 40, 8, dmdBuff );
delay(300);
if(digitalRead(bLEFT) == LOW && digitalRead(bRIGHT) == LOW) {
dmd.clearScreen();
delay(debounce);
setBrightness:
Brightness = EEPROM.read(0);
if(digitalRead(bLEFT) == LOW ){delay(debounce); Brightness++;}
if(digitalRead(bRIGHT) == LOW){delay(debounce); Brightness--;}
EEPROM.write(0,Brightness);
dmd.setBrightness(Brightness);
sprintf(dmdBuff,"%3d ",Brightness);
dmd.drawString( 16, 0, dmdBuff );
delay(50);
if(digitalRead(bCLEAR) == 0){dmd.clearScreen(); delay(debounce); loop();}
else{goto setBrightness;}
}
}



*buttom no control .



