Page 1 of 1

Please Help.me

Posted: Wed Sep 04, 2019 9:01 am
by thepui2008
// Menyisipkan File library
#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;}
}
}

:?: :?: :?: Problem IS....
*buttom no control .
:?: :?: :?: :?:

Re: Please Help.me

Posted: Wed Sep 04, 2019 10:44 am
by Brissieboy
From a quick look, you need to re-think how you are reading and 'debouncing' the buttons. There are lots of resources available to give you some information on debouncing. You would be much better off doing the read & debounce task in a timed interrupt.

Re: Please Help.me

Posted: Wed Sep 04, 2019 2:23 pm
by thepui2008
Thank you so much " Brissieboy "
Quations :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?:
*From this source , how many free ports ?

Re: Please Help.me

Posted: Wed Sep 04, 2019 9:17 pm
by stryker
You can debounce using delay as you're trying, but you'll need to remember the past value of the switch.
Jeremy Blum's tutorials are very good I found : here's one for hardware debouncing with an interrupt and in this one he covers software debouncing

Re: Please Help.me

Posted: Wed Sep 04, 2019 11:39 pm
by Brissieboy
I really like this routine for debouncing. It is quick and very efficient, and it really does work.
You will need to modify it to suit your monitored inputs.
I have used modified versions of this one several times using Timer1 at around 5 to 10 milliSeconds

Code: Select all

Timer1.initialize( 10000 );   // 10000uS = 10mSec
with the debounce attached to the interrupt with

Code: Select all

Timer1.attachInterrupt(debounce);
I could help with this if you really need it, but you will learn a lot more by working it out yourself.
As you are using delay() a lot during your sketch, that approach will not work very well for debouncing.

Re: Please Help.me

Posted: Thu Sep 05, 2019 7:18 am
by Brissieboy
I have sent you some details in a PM as requested.

Re: Please Help.me

Posted: Thu Sep 05, 2019 8:08 am
by thepui2008
Thank you,Thank you so much. Thank you very much. My friend in webboard " stryker, Brissieboy "
I will be more try. :shock: :shock: :shock: :shock: :shock: :shock: