Wave Shield with keypad?


looking @ wavehc library example of "play wave file way through once, allow other buttons interrupt", having trouble understanding defining pins buttons?

code: [select]

// here define buttons we'll use. button "1" first, button "6" 6th, etc
byte buttons[] = {14, 15, 16, 17, 18, 19};


what these numbers represent? last time checked don't have 19 digital pins :) guidance?

here full example:

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
 for (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;
 for (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 1  :(
   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;

 for (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() {
 byte i;
 
 if (justpressed[0]) {
   justpressed[0] = 0;
   playfile("do.wav");
 }
 else if (justpressed[1]) {
     justpressed[1] = 0;
     playfile("re.wav");
 }
 else if (justpressed[2]) {
     justpressed[2] = 0;
     playfile("mi.wav");
 }
 else if (justpressed[3]) {
     justpressed[3] = 0;
     playfile("fa.wav");
 }
 else if (justpressed[4]) {
     justpressed[4] = 0;
     playfile("so.wav");
 }
 else if (justpressed[5]) {
     justpressed[5] = 0;
     playfile("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();
}

quote
last time checked don't have 19 digital pins :) guidance?

check again, then.

if have duemilanove (or other variation 13 digital pins , 6 analog pins), analog pins can used digital pins. numbered 14 through 19.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Wave Shield with keypad?


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums