Connecting UNO with a DF Player applying OneWireKeypad Library
&
With this finely working code below :
#include "OnewireKeypad.h" // OneWireKeypad Library
char KEYS[] = // Define keys' values of Keypad
{
'1', '2', '3', 'A',
'4', '5', '6', 'B',
'7', '8', '9', 'C',
'*', '0', '#', 'D'
};
/* Define Library :
OnewireKeypad <Print, #of buttons>
Keypad(Serial, Char values, #Rows, #Cols, Arduino Pin, Row_resistor, Columns_resistor) */
OnewireKeypad <Print, 16 > Keypad(Serial, KEYS, 4, 4, A0, 4700, 1000);
int ledpin = 2;
#include <DFPlayerMini_Fast.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial1(3, 1); // RX, TX
DFPlayerMini_Fast player1;
void setup ()
{
Serial.begin(9600);
pinMode(ledpin, OUTPUT);
mySerial1.begin(9600);
if(player1.begin(mySerial1, false))
{
player1.volume(12);
player1.play(11);
}
}
void loop()
{
Keypad.SetHoldTime(50); // Key held time in ms
Keypad.SetDebounceTime(25); // Key Debounce time in ms
if ((Keypad.Key_State() == 3)) // not pressed = 0, pressed = 1, released = 2, held = 3
{
char keypress = Keypad.Getkey(); // put value of key pressed in variable 'keypress'
Serial.print("Keypad Key: ");
Serial.println(keypress); // Display value on Serial Monitor
// while ((Keypad.Key_State())) {} // Stay here while Key is held down
if(keypress=='1')
{
player1.loop(14);
}
if(keypress=='2')
{
player1.loop(15);
}
if(keypress=='A')
{
player1.stop();
}
}
}
I am facing 2 small problems
-
There is a very very small delay between the trigger and sound play when a key on keypad is pressed.
It is very small but can effect many of the project programs so want to remove it completely -
While keep pressing the key or say doing press and hold function, the system continue triggers the assigned file from beginning depending on
Keypad.SetHoldTime(50);
Both the above points are dependent on SetHoldTime
If I am decreasing the value then the delay is getting shorten and shorten thus triggering the exact time of key press
But at the same moment it triggers file 2 3 times in the meantime
or
If there is any delay in releasing the key then it starts triggering the file continuously from beginning
I just want to remove this repeatedly triggering from the system
It is like :
If I press a key and hold it
It ll trigger the file once only
&
To trigger it again I ll have to release the key and press it back again. . .
Just exactly like
if(!digitalRead(Pin1))
{
player1.loop(10);
while(!digitalRead(Pin1));
}
Please Guide !!!!!
