2 years ago
arduino code to control the $5 MP3 player
//connect buttons with pull down resistors
int buttonPin = 9; //solder wires to the mp3 player’s “play” button and connect to this pin
int ledPin = 13; //turns on the onboard led
int softPin = 6; //connect your soft switch to this pin
int buttonState = 0; //variable for reading the softswitch state
void setup (){
pinMode(buttonPin, OUTPUT); //sets buttonPin to be an output
pinMode(ledPin, OUTPUT); //sets ledPin to be an output
pinMode(softPin, INPUT); //sets softPin to be an input
}
void loop(){
buttonState = digitalRead(softPin); //read the state of the softswitch
//if it is pressed then buttonState = HIGH;
if (buttonState == HIGH){
digitalWrite(buttonPin, HIGH);
digitalWrite(ledPin, HIGH);
delay(1150); //1150 minimum # for it to trigger playback
digitalWrite(buttonPin, LOW);
delay(8000); //delay is how long of the sample is played
digitalWrite(buttonPin, HIGH);
delay(1500); //this turns the sound off; needs to be above 1150ms (1500)
digitalWrite(buttonPin, LOW);
}
else{
digitalWrite(buttonPin, LOW);
digitalWrite(ledPin, LOW);
}
}
