#include <LiquidCrystal.h>
#include <SPI.h>
#include <SdFat.h>
#include <SFEMP3Shield.h>
#include <Bounce2.h>
#define q1 28
#define q2 26
#define q4 24
#define q8 22
#define B_PLAY A0
#define BUTTON_DEBOUNCE_PERIOD 20 //ms
SdFat sd;
SFEMP3Shield MP3player;
Bounce b_Play = Bounce();
int8_t current_track = 0;
const int rs = 10, en = 5, d4 = 46, d5 = 44, d6 = 42, d7 = 40;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(" Presiona Call");
delay(1000);
lcd.setCursor(0,1);
lcd.print(" para comenzar");
Serial.begin(9600);
Serial.println(readSwitch()); // sends switch value to serial monitor box
pinMode(q1, INPUT); // thumbwheel ‘1’
pinMode(q2, INPUT); // thumbwheel ‘2’
pinMode(q4, INPUT); // thumbwheel ‘4’
pinMode(q8, INPUT); // thumbwheel ‘8’
}
int readSwitch()
{
int total=0;
if (digitalRead(q1)==HIGH) { total+=1; }
if (digitalRead(q2)==HIGH) { total+=2; }
if (digitalRead(q4)==HIGH) { total+=4; }
if (digitalRead(q8)==HIGH) { total+=8; }
return total;
Serial.begin(9600);
pinMode(B_PLAY, INPUT_PULLUP);
b_Play.attach(B_PLAY);
b_Play.interval(BUTTON_DEBOUNCE_PERIOD);
if(!sd.begin(9, SPI_HALF_SPEED)) sd.initErrorHalt();
if (!sd.chdir("/")) sd.errorHalt(“sd.chdir”);
MP3player.begin();
MP3player.setVolume(10,10);
Serial.println(F(“Looking for Buttons to be depressed…”));
}
void loop() {
if (b_Play.update()) {
if (b_Play.read() == LOW) {
Serial.print(F("B_PLAY pressed, Start Playing Track # "));
Serial.println(current_track);
MP3player.playTrack(current_track);
}
}
}