You are on page 1of 4

/*----------------------------------------------------------------------*

Example sketch for Arduino Button Library by Jack Christensen


* *
The simplest example. Using a tactile button switch to turn
the Arduino's pin 13 LED on and off. Wire a switch from Arduino
pin 2 to ground.
* *
This work is licensed under the Creative Commons Attribution-
ShareAlike 3.0 Unported License. To view a copy of this license,
visit http://creativecommons.org/licenses/by-sa/3.0/ or send a
letter to Creative Commons, 171 Second Street, Suite 300,
San Francisco, California, 94105, USA.
----------------------------------------------------------------------*/

#include <Button.h> //https://github.com/JChristensen/Button

#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>

#define BUTTON_PIN1 4
#define BUTTON_PIN2 5
#define BUTTON_PIN3 6
#define BUTTON_PIN4 7
#define BUTTON_PIN5 8
#define BUTTON_PIN6 9
#define BUTTON_PIN7 10
#define BUTTON_PIN8 11
#define BUTTON_PIN9 12
#define BUTTON_PIN10 13

#define PULLUP true //To keep things simple, we use the Arduino's internal
pullup resistor.
#define INVERT true //Since the pullup resistor will keep the pin high
unless the
//switch is closed, this is negative logic, i.e. a high state
//means the button is NOT pressed. (Assuming a normally open switch.)
#define DEBOUNCE_MS 20 //A debounce time of 20 milliseconds usually works well
for tactile button switches.
int a;
int b;
int c;
int d;

SoftwareSerial mySoftwareSerial(2, 3); // RX, TX

Button myBtn1(BUTTON_PIN1, PULLUP, INVERT, DEBOUNCE_MS); //Declare the button


Button myBtn2(BUTTON_PIN2, PULLUP, INVERT, DEBOUNCE_MS); //Declare the button
Button myBtn3(BUTTON_PIN3, PULLUP, INVERT, DEBOUNCE_MS); //Declare the button
Button myBtn4(BUTTON_PIN4, PULLUP, INVERT, DEBOUNCE_MS); //Declare the button
Button myBtn5(BUTTON_PIN5, PULLUP, INVERT, DEBOUNCE_MS); //Declare the button
Button myBtn6(BUTTON_PIN6, PULLUP, INVERT, DEBOUNCE_MS); //Declare the button
Button myBtn7(BUTTON_PIN7, PULLUP, INVERT, DEBOUNCE_MS); //Declare the button
Button myBtn8(BUTTON_PIN8, PULLUP, INVERT, DEBOUNCE_MS); //Declare the button
Button myBtn9(BUTTON_PIN9, PULLUP, INVERT, DEBOUNCE_MS); //Declare the button
Button myBtn10(BUTTON_PIN10, PULLUP, INVERT, DEBOUNCE_MS); //Declare the button

boolean ledState; //A variable that keeps the current LED status

DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);

void setup(void)
{
mySoftwareSerial.begin(9600);
Serial.begin(9600);

Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));

if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate


with mp3.
Serial.println(F("Unable to begin:"));
Serial.println(F("1.Please recheck the connection!"));
Serial.println(F("2.Please insert the SD card!"));
while (true);
}
Serial.println(F("DFPlayer Mini online."));

myDFPlayer.volume(30); //Set volume value. From 0 to 30


//myDFPlayer.play(1); //Play the first mp3
}

void surya()
{

void loop(void)
{
// myBtn1.read(); //Read the button
// if (myBtn1.wasReleased()) { //If the button was released, change the
LED state
// myDFPlayer.play(y);
// Serial.println("tessss");
// }

// for ( i=1; i<=10; i+1)


// {
fungsi();
a = 0;
while (a < 3) {

fungsi();
myBtn1.read(); //Read the button
if (myBtn1.wasReleased()) { //If the button was released, change the LED
state
myDFPlayer.play(a);
a++;
Serial.println(a);
}
}

fungsi();
b = 3;
while (b < 6) {
fungsi();
myBtn2.read(); //Read the button
if (myBtn2.wasReleased()) { //If the button was released, change the LED
state
myDFPlayer.play(b);
b++;
Serial.println(b);
}
}

fungsi();
c = 6;
while (c < 8) {
fungsi();
myBtn3.read(); //Read the button
if (myBtn3.wasReleased()) { //If the button was released, change the LED
state
myDFPlayer.play(c);
c++;
Serial.println(c);
}
}

fungsi();
d = 8;
while (d < 10) {
fungsi();
myBtn4.read(); //Read the button
if (myBtn4.wasReleased()) { //If the button was released, change the LED
state
myDFPlayer.play(d);
d++;
Serial.println(d);

}
}
}

void fungsi () {
myBtn5.read(); //Read the button
if (myBtn5.wasReleased()) { //If the button was released, change the LED
state
myDFPlayer.pause(); //pause the mp3
Serial.println("play");
}

myBtn6.read(); //Read the button


if (myBtn6.wasReleased()) { //If the button was released, change the LED
state
myDFPlayer.start(); //pause the mp3
Serial.println("pause");
}

myBtn7.read(); //Read the button


if (myBtn7.wasReleased()) { //If the button was released, change the LED
state
myDFPlayer.volume(23);
Serial.println("volume down");
}
myBtn8.read(); //Read the button
if (myBtn8.wasReleased()) { //If the button was released, change the LED
state
myDFPlayer.volume(30);
Serial.println("volume up");
}
}

You might also like