Ok, Now i got a toggle switch code (working smoothly), where i am trying to merge
this
tmrpcm.play("1.wav");
&
this
tmrpcm.stopPlayback();
for play and stop operation of a song with same input button at pin 2
Here is the code
#include <stdio.h>
#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 10
TMRpcm tmrpcm;
// constants won't change
const int BUTTON_PIN = 2; // Arduino pin connected to button's pin
const int LED_PIN = 5; // Arduino pin connected to LED's pin
// variables will change:
int ledState = LOW; // the current state of LED
int lastButtonState; // the previous state of button
int currentButtonState; // the current state of button
void setup() {
tmrpcm.speakerPin = (9);
//Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin))
{
Serial.println("SD fail");
return;
}
tmrpcm.setVolume(5);
tmrpcm.play("0.wav");
Serial.begin(9600); // initialize serial
pinMode(BUTTON_PIN, INPUT_PULLUP); // set arduino pin to input pull-up mode
pinMode(LED_PIN, OUTPUT); // set arduino pin to output mode
currentButtonState = digitalRead(BUTTON_PIN);
}
void loop() {
lastButtonState = currentButtonState; // save the last state
currentButtonState = digitalRead(BUTTON_PIN); // read new state
if(lastButtonState == HIGH && currentButtonState == LOW)
{
Serial.println("The button is pressed");
tmrpcm.play("1.wav");
// toggle state of LED
ledState = !ledState;
// control LED arccoding to the toggled state
digitalWrite(LED_PIN, ledState);
}
}
PLEASE LET ME KNOW IF MY ASSUMPTION IS RIGHT OR JUST A DREAMING ARTICLE