[code hl="1, 4, 8"]
#include //library freetronics dmd2
#include // library font
#include // library eeprom
#include // software serial
SoftwareSerial mySerial (2,3); // softwareserial
#include //library dfplayer
// Defining function
#define bCLEAR A1
#define bRIGHT A2
#define bLEFT A0
#define bRIGHTmin A4
#define bLEFTmin A3
#define Panjang 2 // Number of height of Display P10
#define Lebar 1 // Number of width of Display P10
SoftDMD dmd(Panjang, Lebar);
// Declaration Variable
byte Brightness;
byte debounce = 100;
int rightScore = 0;
int leftScore = 0;
int antri = 0;
int i;
char dmdBuff[10];
char BT;
// Setup function, done once arduino reset
void setup() {
Brightness = EEPROM.read(0);
dmd.setBrightness(10);
dmd.selectFont(MyBigFont);
dmd.begin();
dmd.clearScreen();
mySerial.begin(9600);
mp3_set_serial(mySerial);
// delay(1);
mp3_set_volume(25);
Serial.begin(9600);
pinMode(bCLEAR,INPUT_PULLUP);
pinMode(bRIGHT,INPUT_PULLUP);
pinMode(bLEFT,INPUT_PULLUP);
pinMode(bRIGHTmin,INPUT_PULLUP);
pinMode(bLEFTmin,INPUT_PULLUP);
blinkDisplay();
}
// Blink Display Function, make the display blink
void blinkDisplay(){
dmd.clearScreen();
delay(300);
sprintf(dmdBuff,"%d",leftScore);
dmd.drawString( 0, 0, dmdBuff );
dmd.drawString( 28, 0, "->" );
sprintf(dmdBuff,"%2d",rightScore);
dmd.drawString( 43, 0, dmdBuff );
delay(300);
dmd.clearScreen();
delay(300);
sprintf(dmdBuff,"%d",leftScore);
dmd.drawString( 0, 0, dmdBuff );
dmd.drawString( 28, 0, "->" );
sprintf(dmdBuff,"%2d",rightScore);
dmd.drawString( 43, 0, dmdBuff );
delay(300);
dmd.clearScreen();
delay(300);
}
//GOAL Function, display GOAL text when input inserted
void GOAL(){
dmd.clearScreen();
delay(400);
dmd.drawString(0, 0, "ANTRI" );
delay(400);
dmd.clearScreen();
delay(400);
dmd.drawString(0, 0, "ANTRI");
delay(1000);
}
// Loop Function, done repeatedly
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();
antri = 0;
blinkDisplay();
BT = 0;
}
if(digitalRead(bRIGHT) == LOW || BT == 'B') {
delay(debounce);
rightScore++;
GOAL();
blinkDisplay();
BT = 0;
}
if(digitalRead(bLEFTmin) == LOW || BT == 'C') {
delay(debounce);
leftScore--;
GOAL();
blinkDisplay();
BT = 0;
}
if(digitalRead(bRIGHTmin) == LOW || BT == 'D') {
delay(debounce);
rightScore--;
GOAL();
blinkDisplay();
BT = 0;
}
sprintf(dmdBuff,"%d",leftScore);
dmd.drawString( 0, 0, dmdBuff );
dmd.drawString( 28, 0, "->" );
sprintf(dmdBuff,"%2d",rightScore);
dmd.drawString( 43, 0, 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;}
}
if ( antri == 0 && leftScore == 1 )
{
mp3_play (60); delay(2000);
mp3_play (70); delay(2000); mp3_play
(1); delay(2000); mp3_play (80);
delay(2000);mp3_play (1); delay(2000);
//antri = 0;
}
if (antri == 0 &&leftScore == 2){
mp3_play (60); delay(2000);
mp3_play (70); delay(2000); mp3_play
(2); delay(2000); mp3_play (80);
delay(2000);mp3_play (1); delay(2000);
//antri = 0;
}
if (antri == 0 &&leftScore == 3){
mp3_play (60); delay(2000);
mp3_play (70); delay(2000); mp3_play
(3); delay(2000); mp3_play (80);
delay(2000);mp3_play (2); delay(2000);
//antri = 0;
}
if (antri == 0 &&leftScore == 4){
mp3_play (60); delay(2000);
mp3_play (70); delay(2000); mp3_play
(4); delay(2000); mp3_play (80);
delay(2000);mp3_play (2); delay(2000);
//antri = 0;
}
[/code]