A nice good working standalone wav player, but i want to use it to play some tracks while i pushing a button on the Ardiuno Uno. That is for a little funfair ride model, when i push a button on the Arduino, the motor is gonna be running and a sound (on the smartwav) is playing.
My question, and i can't find the answer in the documents, dont on Arduino smartwave example page, not on the forum here, but its must be easy i think.
A example INO file with in
Push a button and play "test.wav" on the smartwave. thats all.
can someone help me with this?
i hope so, als on Arduino and Smartwave site says, there wil be examples soon..... wel that 3 years ago
this is what i have build but he doens't work, i see nothing happend , communicate with rx and tx is maybe problem?
this is the code:
#include <SMARTWAV.h> //include the SMARTWAV library!
SMARTWAV sWav; //create our object called sWAV (smartWAV)
const int button = A0; // the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status
void setup() { //initial setup
//This function must always be called for SMARTWAV support
sWav.init(); //configure the serial and pinout of arduino board for SMARTWAV support
sWav.reset(); //perform an initial reset
pinMode(1,OUTPUT);
pinMode(0,INPUT);
Serial.begin(9600);
}
void loop() { //main loop
delay(1000);
if (buttonState == HIGH) { //write the code that checks if the button is pressed
sWav.playTrackName("test"); //call the song by it's name, don't add the ".wav" extension
}
}
#include <SMARTWAV.h> //include the SMARTWAV library!
SMARTWAV sWav; //create our object called sWAV (smartWAV)
const int buttonPin = 2; // TRY PIN 2 OR OTHER PINS ON THE RIGHT SIDE OF YOUR UNO for eg
int buttonState = 0; // SET IT TO 0
void setup() { //initial setup
//This function must always be called for SMARTWAV support
sWav.init(); //configure the serial and pinout of arduino board for SMARTWAV support
sWav.reset(); //perform an initial reset
pinMode(2,INPUT); // CONNECT A 10K RESISTOR FROM PIN 2 TO GROUND AS IN THE DIAGRAM
}
void loop() { //main loop
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) // WHEN YOU PRESS THE BUTTON THE BUTTONSTATE GOES FROM LOW TO HIGH
{
sWav.playTrackName("test"); //call the song by it's name, don't add the ".wav" extension
}
}
I have build this and we are a little further right now
have tx and rx on the 2 and 3 pins and a resset on pin 4, when i push the resset button on the arduino, and (strange) tip with my finger on the arduino, he plays de test.wav.
when i pressed the button on A0 there nothings gonne play anymore, it seems that it working 1 and not when mpressed the button but when comes with my finger to the arduino, seems like something about inteferentie.
this is the code i used and test it:
#include <SMARTWAV.h> //include the SMARTWAV library!
SMARTWAV sWav; //create our object called sWAV (smartWAV)
const int buttonPin = A0; // TRY PIN 2 OR OTHER PINS ON THE RIGHT SIDE OF YOUR UNO for eg
int buttonState = 0; // SET IT TO 0
void setup() { //initial setup
//This function must always be called for SMARTWAV support
sWav.init(); //configure the serial and pinout of arduino board for SMARTWAV support
sWav.reset(); //perform an initial reset
}
void loop() { //main loop
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) // WHEN YOU PRESS THE BUTTON THE BUTTONSTATE GOES FROM LOW TO HIGH
{
sWav.playTrackName("test"); //call the song by it's name, don't add the ".wav" extension
}
}
when i dont used the resset cable, the sketch wil be playing directly after the arduino resset.
so what can this be? i have 2 smartwav and both have the same effect.
Also same when i use pin 7 for the button, or A0 it does't matter.
Thanks everybody, its working now
I have change the button and the way to tricker it.
But i have other question also, maybe its a little thing.
when i push the button, the led wil be on and wav wil be play, what i want is when i push the button again, he must play a other wav file, lets say test2.wav.
when thats oke, than he must play de the first again.
i mean this:
#include <SMARTWAV.h> //include the SMARTWAV library!
SMARTWAV sWav; //create our object called sWAV (smartWAV)
int led = 12;
void setup() { //initial setup
//This function must always be called for SMARTWAV support
sWav.init(); //configure the serial and pinout of arduino board for SMARTWAV support
sWav.reset(); //perform an initial reset
pinMode(7, INPUT);
pinMode(led, OUTPUT);
digitalWrite(7, HIGH);
}
void loop() { //first time
if (digitalRead(7) == LOW) // WHEN PRESS IT FOR THE FIRST TIME
{
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
sWav.playTrackName("test"); //call the song by it's name, don't add the ".wav" extension
delay(10000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
}
}
void loop() { //second time
if (digitalRead(7) == LOW) // WHEN PRESS IT FOR THE SECOND TIME
{
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
sWav.playTrackName("test2"); //call the song by it's name, don't add the ".wav" extension
delay(10000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
}
}
I have found a sketch to combine it, so i can work further with my project.
When the mini fairfair is ready i show what he Arduino do for this project.
press the same button the second time to play the next song
and then so on
when it reaches the end of your song list
it goes back to the first one
if you do not need to debug it with your serial monitor , just remove the code for that
const int buttonPin = 2; // the pin that the pushbutton is attached to
const int ledPin = 8; // the pin that the LED is attached to
const int ledPin2 = 9;
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT); // initialize serial communication:
Serial.begin(9600);
}
void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
}
else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("off");
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
counting1();
counting2();
resett();
}
void resett() {
if (buttonPushCounter==3)
{ buttonPushCounter = 1;
delay(20);}
}
void counting1() {
if (buttonPushCounter==1) {
delay(20);
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
void counting2() {
if (buttonPushCounter==2) {
delay(20);
digitalWrite(ledPin2, HIGH);
} else {
digitalWrite(ledPin2, LOW);
}
}
this is my rookie way of doing it according to the button count example