Wave Shield Code Question
code: [select]
#include <fatreader.h>
#include <sdreader.h>
#include <avr/pgmspace.h>
#include "waveutil.h"
#include "wavehc.h"
sdreader card; // object holds information card
fatvolume vol; // holds information partition on card
fatreader root; // holds information filesystem on card
fatreader f; // holds information file we're play
wavehc wave; // wave (audio) object, since play 1 @ time
//#define debounce 5 // button debouncer
//
//// here define buttons we'll use. button "1" first, button "6" 6th, etc
//byte buttons[] = {14, 15, 16, 17, 18, 19};
//// handy macro lets determine how big array above is, checking size
//#define numbuttons sizeof(buttons)
//// track if button pressed, released, or 'pressed' (the current state
//volatile byte pressed[numbuttons], justpressed[numbuttons], justreleased[numbuttons];
// handy function return number of bytes free in ram, great debugging!
int freeram(void)
{
extern int __bss_end;
extern int *__brkval;
int free_memory;
if((int)__brkval == 0) {
free_memory = ((int)&free_memory) - ((int)&__bss_end);
}
else {
free_memory = ((int)&free_memory) - ((int)__brkval);
}
return free_memory;
}
void sderrorcheck(void)
{
if (!card.errorcode()) return;
putstring("\n\rsd i/o error: ");
serial.print(card.errorcode(), hex);
putstring(", ");
serial.println(card.errordata(), hex);
while(1);
}
void setup() {
byte i;
// set serial port
serial.begin(9600);
putstring_nl("wavehc ");
// serial.print(numbuttons, dec);
// putstring_nl("buttons");
putstring("free ram: "); // can debugging, running out of ram bad
serial.println(freeram()); // if under 150 bytes may spell trouble!
// set output pins dac control. pins defined in library
pinmode(2, output);
pinmode(3, output);
pinmode(4, output);
pinmode(5, output);
// pin13 led
pinmode(13, output);
// // make input & enable pull-up resistors on switch pins
// (i=0; i< numbuttons; i++) {
// pinmode(buttons[i], input);
// digitalwrite(buttons[i], high);
// }
// if (!card.init(true)) { //play 4 mhz spi if 8mhz isn't working you
if (!card.init()) { //play 8 mhz spi (default faster!)
putstring_nl("card init. failed!"); // went wrong, lets print out why
sderrorcheck();
while(1); // 'halt' - nothing!
}
// enable optimize read - cards may timeout. disable if you're having problems
card.partialblockread(true);
// fat partition!
uint8_t part;
(part = 0; part < 5; part++) { // have 5 slots in
if (vol.init(card, part))
break; // found one, lets bail
}
if (part == 5) { // if ended not finding one :(
putstring_nl("no valid fat partition!");
sderrorcheck(); // went wrong, lets print out why
while(1); // 'halt' - nothing!
}
// lets tell user found
putstring("using partition ");
serial.print(part, dec);
putstring(", type fat");
serial.println(vol.fattype(),dec); // fat16 or fat32?
// try open root directory
if (!root.openroot(vol)) {
putstring_nl("can't open root dir!"); // went wrong,
while(1); // 'halt' - nothing!
}
// whew! got past tough parts.
putstring_nl("ready!");
tccr2a = 0;
tccr2b = 1<<cs22 | 1<<cs21 | 1<<cs20;
//timer2 overflow interrupt enable
timsk2 |= 1<<toie2;
}
//signal(timer2_ovf_vect) {
// check_switches();
//}
//
//void check_switches()
//{
// static byte previousstate[numbuttons];
// static byte currentstate[numbuttons];
// byte index;
//
// (index = 0; index < numbuttons; index++) {
// currentstate[index] = digitalread(buttons[index]); // read button
//
/*
serial.print(index, dec);
serial.print(": cstate=");
serial.print(currentstate[index], dec);
serial.print(", pstate=");
serial.print(previousstate[index], dec);
serial.print(", press=");
*/
//
// if (currentstate[index] == previousstate[index]) {
// if ((pressed[index] == low) && (currentstate[index] == low)) {
// // pressed
// justpressed[index] = 1;
// }
// else if ((pressed[index] == high) && (currentstate[index] == high)) {
// // released
// justreleased[index] = 1;
// }
// pressed[index] = !currentstate[index]; // remember, digital high means not pressed
// }
// //serial.println(pressed[index], dec);
// previousstate[index] = currentstate[index]; // keep running tally of buttons
// }
//}
void loop(){
playcomplete("songone.wav");
// if (counter == 1){
//
// playcomplete("songone.wav");
// }
// else if (counter == 2){
//
// playcomplete("songtwo.wav");
// }
// else if (counter == 3){
//
// playcomplete("songthree.wav");
}
// if (justpressed[0]) {
// justpressed[0] = 0;
// playcomplete("do.wav");
// }
// if (justpressed[1]) {
// justpressed[1] = 0;
// playcomplete("re.wav");
// }
// if (justpressed[2]) {
// justpressed[2] = 0;
// playcomplete("mi.wav");
// }
// if (justpressed[3]) {
// justpressed[3] = 0;
// playcomplete("fa.wav");
// }
// if (justpressed[4]) {
// justpressed[4] = 0;
// playcomplete("so.wav");
// }
// if (justpressed[5]) {
// justpressed[5] = 0;
// playcomplete("la.wav");
// }
// plays full file beginning end no pause.
void playcomplete(char *name) {
// call our helper find , play name
playfile(name);
while (wave.isplaying) {
// nothing while playing
}
// done playing
}
void playfile(char *name) {
// see if wave object doing something
if (wave.isplaying) {// playing something, stop it!
wave.stop(); // stop it
}
// in root directory , open file
if (!f.open(root, name)) {
putstring("couldn't open file "); serial.print(name); return;
}
// ok read file , turn wave object
if (!wave.create(f)) {
putstring_nl("not valid wav"); return;
}
// ok time play! start playback
wave.play();
}
i've made work before, not today. compiles fine on serial monitor shows bunch of this:wavehc
free ram: 676
wavehc
free
free ram: 676
wavehc
free ram: 676
wavehc
free ram: 676
wavehc
free ram: 676
is commented out code part of problem, or not? if not, rid of it!.
clearly, doing causing arduino reset. add more serial.print() statements, see getting to/not getting to. code between gets , not problem.
clearly, doing causing arduino reset. add more serial.print() statements, see getting to/not getting to. code between gets , not problem.
Arduino Forum > Using Arduino > Programming Questions > Wave Shield Code Question
arduino
Comments
Post a Comment