Difference between revisions of "Students/Ian Petrov"

From Robert-Depot
Jump to: navigation, search
Line 42: Line 42:
 
Code
 
Code
 
----
 
----
//Ian Petrov VIS147A Final
+
[quote]
//code edited from Adafruit Wave Shield Site
+
[color=#7E7E7E]//Ian Petrov VIS147A Final[/color]
#include <FatReader.h>
+
[color=#7E7E7E]//code edited from Adafruit Wave Shield Site[/color]
#include <SdReader.h>
+
#include <FatReader.h>
#include <avr/pgmspace.h>
+
#include <SdReader.h>
#include "WaveUtil.h"
+
#include <avr/pgmspace.h>
#include "WaveHC.h"
+
#include [color=#006699]"WaveUtil.h"[/color]
 +
#include [color=#006699]"WaveHC.h"[/color]
  
  
SdReader card;   // This object holds the information for the card
+
SdReader card;    [color=#7E7E7E]// This object holds the information for the card[/color]
FatVolume vol;   // This holds the information for the partition on the card
+
FatVolume vol;    [color=#7E7E7E]// This holds the information for the partition on the card[/color]
FatReader root;   // This holds the information for the filesystem on the card
+
FatReader root;   [color=#7E7E7E]// This holds the information for the filesystem on the card[/color]
FatReader f;     // This holds the information for the file we're play
+
FatReader f;      [color=#7E7E7E]// This holds the information for the file we're play[/color]
  
WaveHC wave;     // This is the only wave (audio) object, since we will only play one at a time
+
WaveHC wave;      [color=#7E7E7E]// This is the only wave (audio) object, since we will only play one at a time[/color]
  
#define DEBOUNCE 100  // button debouncer
+
#define DEBOUNCE 100  [color=#7E7E7E]// button debouncer[/color]
  
// this handy function will return the number of bytes currently free in RAM, great for debugging!  
+
[color=#7E7E7E]// this handy function will return the number of bytes currently free in RAM, great for debugging!   [/color]
int freeRam(void)
+
[color=#CC6600]int[/color] freeRam([color=#CC6600]void[/color])
 
{
 
{
  extern int  __bss_end;  
+
  extern [color=#CC6600]int[/color] __bss_end;  
  extern int  *__brkval;  
+
  extern [color=#CC6600]int[/color] *__brkval;  
  int free_memory;  
+
  [color=#CC6600]int[/color] free_memory;  
  if((int)__brkval == 0) {
+
  [color=#CC6600]if[/color](([color=#CC6600]int[/color])__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end);  
+
    free_memory = (([color=#CC6600]int[/color])&free_memory) - (([color=#CC6600]int[/color])&__bss_end);  
  }
+
  }
  else {
+
  [color=#CC6600]else[/color] {
    free_memory = ((int)&free_memory) - ((int)__brkval);  
+
    free_memory = (([color=#CC6600]int[/color])&free_memory) - (([color=#CC6600]int[/color])__brkval);  
  }
+
  }
  return free_memory;  
+
  [color=#CC6600]return[/color] free_memory;  
}  
+
} 
  
void sdErrorCheck(void)
+
[color=#CC6600]void[/color] sdErrorCheck([color=#CC6600]void[/color])
 
{
 
{
  if (!card.errorCode()) return;
+
  [color=#CC6600]if[/color] (!card.errorCode()) [color=#CC6600]return[/color];
  putstring("\n\rSD I/O error: ");
+
  putstring([color=#006699]"\n\rSD I/O error: "[/color]);
  Serial.print(card.errorCode(), HEX);
+
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](card.errorCode(), [color=#006699]HEX[/color]);
  putstring(", ");
+
  putstring([color=#006699]", "[/color]);
  Serial.println(card.errorData(), HEX);
+
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]println[/color](card.errorData(), [color=#006699]HEX[/color]);
  while(1);
+
  [color=#CC6600]while[/color](1);
 
}
 
}
  
void setup() {
+
[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]() {
  // set up serial port
+
  [color=#7E7E7E]// set up serial port[/color]
  Serial.begin(9600);
+
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]begin[/color](9600);
  putstring_nl("WaveHC with 6 buttons");
+
  putstring_nl([color=#006699]"WaveHC with 6 buttons"[/color]);
 
+
  
  putstring("Free RAM: ");      // This can help with debugging, running out of RAM is bad
+
   putstring([color=#006699]"Free RAM: "[/color]);      [color=#7E7E7E]// This can help with debugging, running out of RAM is bad[/color]
  Serial.println(freeRam());      // if this is under 150 bytes it may spell trouble!
+
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]println[/color](freeRam());      [color=#7E7E7E]// if this is under 150 bytes it may spell trouble![/color]
 
+
  
  // Set the output pins for the DAC control. This pins are defined in the library
+
  [color=#7E7E7E]// Set the output pins for the DAC control. This pins are defined in the library[/color]
  pinMode(2, OUTPUT);
+
  [color=#CC6600]pinMode[/color](2, [color=#006699]OUTPUT[/color]);
  pinMode(3, OUTPUT);
+
  [color=#CC6600]pinMode[/color](3, [color=#006699]OUTPUT[/color]);
  pinMode(4, OUTPUT);
+
  [color=#CC6600]pinMode[/color](4, [color=#006699]OUTPUT[/color]);
  pinMode(5, OUTPUT);
+
  [color=#CC6600]pinMode[/color](5, [color=#006699]OUTPUT[/color]);
+
 
  // pin13 LED
+
  [color=#7E7E7E]// pin13 LED[/color]
  pinMode(13, OUTPUT);
+
  [color=#CC6600]pinMode[/color](13, [color=#006699]OUTPUT[/color]);
+
 
  // enable pull-up resistors on switch pins (analog inputs)
+
  [color=#7E7E7E]// enable pull-up resistors on switch pins (analog inputs)[/color]
  digitalWrite(14, HIGH);
+
  [color=#CC6600]digitalWrite[/color](14, [color=#006699]HIGH[/color]);
  digitalWrite(15, HIGH);
+
  [color=#CC6600]digitalWrite[/color](15, [color=#006699]HIGH[/color]);
  digitalWrite(16, HIGH);
+
  [color=#CC6600]digitalWrite[/color](16, [color=#006699]HIGH[/color]);
  digitalWrite(17, HIGH);
+
  [color=#CC6600]digitalWrite[/color](17, [color=#006699]HIGH[/color]);
  digitalWrite(18, HIGH);
+
  [color=#CC6600]digitalWrite[/color](18, [color=#006699]HIGH[/color]);
  digitalWrite(19, HIGH);
+
  [color=#CC6600]digitalWrite[/color](19, [color=#006699]HIGH[/color]);
+
 
  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
+
  [color=#7E7E7E]//  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you[/color]
  if (!card.init()) {        //play with 8 MHz spi (default faster!)   
+
  [color=#CC6600]if[/color] (!card.init()) {        [color=#7E7E7E]//play with 8 MHz spi (default faster!)  [/color]
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
+
    putstring_nl([color=#006699]"Card init. failed!"[/color]);  [color=#7E7E7E]// Something went wrong, lets print out why[/color]
    sdErrorCheck();
+
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
+
    [color=#CC6600]while[/color](1);                            [color=#7E7E7E]// then 'halt' - do nothing![/color]
  }
+
  }
 
+
  
  // enable optimize read - some cards may timeout. Disable if you're having problems
+
  [color=#7E7E7E]// enable optimize read - some cards may timeout. Disable if you're having problems[/color]
  card.partialBlockRead(true);
+
  card.partialBlockRead([color=#CC6600]true[/color]);
+
 
// Now we will look for a FAT partition!
+
[color=#7E7E7E]// Now we will look for a FAT partition![/color]
  uint8_t part;
+
  uint8_t part;
  for (part = 0; part < 5; part++) {    // we have up to 5 slots to look in
+
  [color=#CC6600]for[/color] (part = 0; part < 5; part++) {    [color=#7E7E7E]// we have up to 5 slots to look in[/color]
    if (vol.init(card, part))  
+
    [color=#CC6600]if[/color] (vol.init(card, part))  
      break;                            // we found one, lets bail
+
      [color=#CC6600]break[/color];                            [color=#7E7E7E]// we found one, lets bail[/color]
  }
+
  }
  if (part == 5) {                      // if we ended up not finding one  :(
+
  [color=#CC6600]if[/color] (part == 5) {                      [color=#7E7E7E]// if we ended up not finding one  :([/color]
    putstring_nl("No valid FAT partition!");
+
    putstring_nl([color=#006699]"No valid FAT partition!"[/color]);
    sdErrorCheck();     // Something went wrong, lets print out why
+
    sdErrorCheck();      [color=#7E7E7E]// Something went wrong, lets print out why[/color]
    while(1);                            // then 'halt' - do nothing!
+
    [color=#CC6600]while[/color](1);                            [color=#7E7E7E]// then 'halt' - do nothing![/color]
  }
+
  }
 
+
  
  // Lets tell the user about what we found
+
  [color=#7E7E7E]// Lets tell the user about what we found[/color]
  putstring("Using partition ");
+
  putstring([color=#006699]"Using partition "[/color]);
  Serial.print(part, DEC);
+
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](part, [color=#006699]DEC[/color]);
  putstring(", type is FAT");
+
  putstring([color=#006699]", type is FAT"[/color]);
  Serial.println(vol.fatType(),DEC);    // FAT16 or FAT32?
+
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]println[/color](vol.fatType(),[color=#006699]DEC[/color]);    [color=#7E7E7E]// FAT16 or FAT32?[/color]
 
+
  
  // Try to open the root directory
+
  [color=#7E7E7E]// Try to open the root directory[/color]
  if (!root.openRoot(vol)) {
+
  [color=#CC6600]if[/color] (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
+
    putstring_nl([color=#006699]"Can't open root dir!"[/color]); [color=#7E7E7E]// Something went wrong,[/color]
    while(1);                            // then 'halt' - do nothing!
+
    [color=#CC6600]while[/color](1);                            [color=#7E7E7E]// then 'halt' - do nothing![/color]
  }
+
  }
 
+
  
  // Whew! We got past the tough parts.
+
  [color=#7E7E7E]// Whew! We got past the tough parts.[/color]
  putstring_nl("Ready!");
+
  putstring_nl([color=#006699]"Ready!"[/color]);
 
}
 
}
  
void playcomplete(char good) {
+
[color=#CC6600]void[/color] playcomplete([color=#CC6600]char[/color] good) {
  // call our helper to find and play this name
+
  [color=#7E7E7E]// call our helper to find and play this name[/color]
  playfile("GOOD.WAV");
+
  playfile([color=#006699]"GOOD.WAV"[/color]);
  while (wave.isplaying) {
+
  [color=#CC6600]while[/color] (wave.isplaying) {
  // do nothing while its playing
+
  [color=#7E7E7E]// do nothing while its playing[/color]
  }
+
  }
  // now its done playing
+
  [color=#7E7E7E]// now its done playing[/color]
 
}
 
}
  
  
void loop() {
+
[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]() {
  //putstring(".");            // uncomment this to see if the loop isnt running   
+
  [color=#7E7E7E]//putstring(".");            // uncomment this to see if the loop isnt running  [/color]
   
+
    
  switch (check_switches()) {    //this is the loop which cycles the arnold sounds based
+
  [color=#CC6600]switch[/color] (check_switches()) {    [color=#7E7E7E]//this is the loop which cycles the arnold sounds based[/color]
    case 1:                      //on which switch you connect to.
+
    [color=#CC6600]case[/color] 1:                      [color=#7E7E7E]//on which switch you connect to.[/color]
      playcomplete("STOP.WAV");
+
      playcomplete([color=#006699]"STOP.WAV"[/color]);
      break;
+
      [color=#CC6600]break[/color];
    case 2:
+
    [color=#CC6600]case[/color] 2:
      playcomplete("SOB.WAV");
+
      playcomplete([color=#006699]"SOB.WAV"[/color]);
      break;
+
      [color=#CC6600]break[/color];
    case 3:
+
    [color=#CC6600]case[/color] 3:
      playcomplete("DONT.WAV");
+
      playcomplete([color=#006699]"DONT.WAV"[/color]);
      break;
+
      [color=#CC6600]break[/color];
    case 4:
+
    [color=#CC6600]case[/color] 4:
      playcomplete("LACK.WAV");
+
      playcomplete([color=#006699]"LACK.WAV"[/color]);
      break;
+
      [color=#CC6600]break[/color];
    case 5:
+
    [color=#CC6600]case[/color] 5:
      playcomplete("FIST.WAV");
+
      playcomplete([color=#006699]"FIST.WAV"[/color]);
  }
+
  }
 
}
 
}
  
byte check_switches()
+
[color=#CC6600]byte[/color] check_switches()
 
{
 
{
  static byte previous[6];
+
  [color=#CC6600]static[/color] [color=#CC6600]byte[/color] previous[6];
  static long time[6];
+
  [color=#CC6600]static[/color] [color=#CC6600]long[/color] time[6];
  byte reading;
+
  [color=#CC6600]byte[/color] reading;
  byte pressed;
+
  [color=#CC6600]byte[/color] pressed;
  byte index;
+
  [color=#CC6600]byte[/color] index;
  pressed = 0;
+
  pressed = 0;
  
  for (byte index = 0; index < 6; ++index) {
+
  [color=#CC6600]for[/color] ([color=#CC6600]byte[/color] index = 0; index < 6; ++index) {
    reading = digitalRead(14 + index);
+
    reading = [color=#CC6600]digitalRead[/color](14 + index);
    if (reading == LOW && previous[index] == HIGH && millis() - time[index] > DEBOUNCE)
+
    [color=#CC6600]if[/color] (reading == [color=#006699]LOW[/color] && previous[index] == [color=#006699]HIGH[/color] && [color=#CC6600]millis[/color]() - time[index] > DEBOUNCE)
    {
+
    {
      // switch pressed
+
      [color=#7E7E7E]// switch pressed[/color]
      time[index] = millis();
+
      time[index] = [color=#CC6600]millis[/color]();
      pressed = index + 1;
+
      pressed = index + 1;
      break;
+
      [color=#CC6600]break[/color];
    }
+
    }
    previous[index] = reading;
+
    previous[index] = reading;
  }
+
  }
  // return switch number (1 - 6)
+
  [color=#7E7E7E]// return switch number (1 - 6)[/color]
  return (pressed);
+
  [color=#CC6600]return[/color] (pressed);
 
}
 
}
  
  
// Plays a full file from beginning to end with no pause.
+
[color=#7E7E7E]// Plays a full file from beginning to end with no pause.[/color]
void playcomplete(char *name) {
+
[color=#CC6600]void[/color] playcomplete([color=#CC6600]char[/color] *name) {
  // call our helper to find and play this name
+
  [color=#7E7E7E]// call our helper to find and play this name[/color]
  playfile(name);
+
  playfile(name);
  while (wave.isplaying) {
+
  [color=#CC6600]while[/color] (wave.isplaying) {
  // do nothing while its playing
+
  [color=#7E7E7E]// do nothing while its playing[/color]
  }
+
  }
  // now its done playing
+
  [color=#7E7E7E]// now its done playing[/color]
 
}
 
}
  
void playfile(char *name) {
+
[color=#CC6600]void[/color] playfile([color=#CC6600]char[/color] *name) {
  // see if the wave object is currently doing something
+
  [color=#7E7E7E]// see if the wave object is currently doing something[/color]
  if (wave.isplaying) {// already playing something, so stop it!
+
  [color=#CC6600]if[/color] (wave.isplaying) {[color=#7E7E7E]// already playing something, so stop it![/color]
    wave.stop(); // stop it
+
    wave.[color=#CC6600]stop[/color](); [color=#7E7E7E]// stop it[/color]
  }
+
  }
  // look in the root directory and open the file
+
  [color=#7E7E7E]// look in the root directory and open the file[/color]
  if (!f.open(root, name)) {
+
  [color=#CC6600]if[/color] (!f.open(root, name)) {
    putstring("Couldn't open file "); Serial.print(name); return;
+
    putstring([color=#006699]"Couldn't open file "[/color]); [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](name); [color=#CC6600]return[/color];
  }
+
  }
  // OK read the file and turn it into a wave object
+
  [color=#7E7E7E]// OK read the file and turn it into a wave object[/color]
  if (!wave.create(f)) {
+
  [color=#CC6600]if[/color] (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
+
    putstring_nl([color=#006699]"Not a valid WAV"[/color]); [color=#CC6600]return[/color];
  }
+
  }
 
+
  
  // ok time to play! start playback
+
  [color=#7E7E7E]// ok time to play! start playback[/color]
  wave.play();
+
  wave.play();
 
}
 
}
 +
 +
[/quote]

Revision as of 02:08, 20 March 2010

I am a Visual Arts - Media major with an interest in graphic design. I was born in Europe, and moved to Canada when I was 5. I've lived in San Diego since I was 10, and graduated from University City High School before coming to UCSD as a transfer. I have been working with computers since grade school, and am highly interested in pursuing a career in the computer field. I have been in interested in electronics also since a young age and I think it will add an interesting dimension to my artistic career, and am eagerly looking forward to learning how to make art projects using them.


DSC_0055-1.jpg

Portable Heater


DSC_0051.jpg

Generator?


DSC_0050.jpg

Air Conditioner


DSC_0049.jpg

Cell Phone


DSC_0046.jpg

Car Keys


Midterm Proposal

My proposal is a hat which contains a cooling fan enabled by a switch. The switch will hang down from the inside of the hat to about shoulder length, enabling the wearer to turn on and off the fan. This is a crude implementation of a warm weather cowboy hat which provides cooling apart from shade. It will be powered by a 9v battery, and connected by a normally open switch. In order to operate the fan, you must hold down the button.


MidDiag.jpg


Final Proposal

My final project will be called "Punch a Celebrity". It will consist of a punching pad with a picture of a celebrity on it. The pad will have an impact sensor attached to a arduino/breakout board, which is attached to a speaker. This will enable a wav or mp3 file to play at the moment of impact, and simulate that you are actually hitting a celebrity.

proposal.png

Code


[quote] [color=#7E7E7E]//Ian Petrov VIS147A Final[/color] [color=#7E7E7E]//code edited from Adafruit Wave Shield Site[/color]

  1. include <FatReader.h>
  2. include <SdReader.h>
  3. include <avr/pgmspace.h>
  4. include [color=#006699]"WaveUtil.h"[/color]
  5. include [color=#006699]"WaveHC.h"[/color]


SdReader card;    [color=#7E7E7E]// This object holds the information for the card[/color] FatVolume vol;    [color=#7E7E7E]// This holds the information for the partition on the card[/color] FatReader root;   [color=#7E7E7E]// This holds the information for the filesystem on the card[/color] FatReader f;      [color=#7E7E7E]// This holds the information for the file we're play[/color]

WaveHC wave;      [color=#7E7E7E]// This is the only wave (audio) object, since we will only play one at a time[/color]

  1. define DEBOUNCE 100  [color=#7E7E7E]// button debouncer[/color]

[color=#7E7E7E]// this handy function will return the number of bytes currently free in RAM, great for debugging!   [/color] [color=#CC6600]int[/color] freeRam([color=#CC6600]void[/color]) {   extern [color=#CC6600]int[/color] __bss_end;   extern [color=#CC6600]int[/color] *__brkval;   [color=#CC6600]int[/color] free_memory;   [color=#CC6600]if[/color](([color=#CC6600]int[/color])__brkval == 0) {     free_memory = (([color=#CC6600]int[/color])&free_memory) - (([color=#CC6600]int[/color])&__bss_end);   }   [color=#CC6600]else[/color] {     free_memory = (([color=#CC6600]int[/color])&free_memory) - (([color=#CC6600]int[/color])__brkval);   }   [color=#CC6600]return[/color] free_memory; } 

[color=#CC6600]void[/color] sdErrorCheck([color=#CC6600]void[/color]) {   [color=#CC6600]if[/color] (!card.errorCode()) [color=#CC6600]return[/color];   putstring([color=#006699]"\n\rSD I/O error: "[/color]);   [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](card.errorCode(), [color=#006699]HEX[/color]);   putstring([color=#006699]", "[/color]);   [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]println[/color](card.errorData(), [color=#006699]HEX[/color]);   [color=#CC6600]while[/color](1); }

[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]() {   [color=#7E7E7E]// set up serial port[/color]   [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]begin[/color](9600);   putstring_nl([color=#006699]"WaveHC with 6 buttons"[/color]);       putstring([color=#006699]"Free RAM: "[/color]); [color=#7E7E7E]// This can help with debugging, running out of RAM is bad[/color]   [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]println[/color](freeRam()); [color=#7E7E7E]// if this is under 150 bytes it may spell trouble![/color]      [color=#7E7E7E]// Set the output pins for the DAC control. This pins are defined in the library[/color]   [color=#CC6600]pinMode[/color](2, [color=#006699]OUTPUT[/color]);   [color=#CC6600]pinMode[/color](3, [color=#006699]OUTPUT[/color]);   [color=#CC6600]pinMode[/color](4, [color=#006699]OUTPUT[/color]);   [color=#CC6600]pinMode[/color](5, [color=#006699]OUTPUT[/color]);     [color=#7E7E7E]// pin13 LED[/color]   [color=#CC6600]pinMode[/color](13, [color=#006699]OUTPUT[/color]);     [color=#7E7E7E]// enable pull-up resistors on switch pins (analog inputs)[/color]   [color=#CC6600]digitalWrite[/color](14, [color=#006699]HIGH[/color]);   [color=#CC6600]digitalWrite[/color](15, [color=#006699]HIGH[/color]);   [color=#CC6600]digitalWrite[/color](16, [color=#006699]HIGH[/color]);   [color=#CC6600]digitalWrite[/color](17, [color=#006699]HIGH[/color]);   [color=#CC6600]digitalWrite[/color](18, [color=#006699]HIGH[/color]);   [color=#CC6600]digitalWrite[/color](19, [color=#006699]HIGH[/color]);     [color=#7E7E7E]// if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you[/color]   [color=#CC6600]if[/color] (!card.init()) { [color=#7E7E7E]//play with 8 MHz spi (default faster!) [/color]     putstring_nl([color=#006699]"Card init. failed!"[/color]); [color=#7E7E7E]// Something went wrong, lets print out why[/color]     sdErrorCheck();     [color=#CC6600]while[/color](1); [color=#7E7E7E]// then 'halt' - do nothing![/color]   }      [color=#7E7E7E]// enable optimize read - some cards may timeout. Disable if you're having problems[/color]   card.partialBlockRead([color=#CC6600]true[/color]);   [color=#7E7E7E]// Now we will look for a FAT partition![/color]   uint8_t part;   [color=#CC6600]for[/color] (part = 0; part < 5; part++) { [color=#7E7E7E]// we have up to 5 slots to look in[/color]     [color=#CC6600]if[/color] (vol.init(card, part))       [color=#CC6600]break[/color]; [color=#7E7E7E]// we found one, lets bail[/color]   }   [color=#CC6600]if[/color] (part == 5) { [color=#7E7E7E]// if we ended up not finding one  :([/color]     putstring_nl([color=#006699]"No valid FAT partition!"[/color]);     sdErrorCheck();      [color=#7E7E7E]// Something went wrong, lets print out why[/color]     [color=#CC6600]while[/color](1); [color=#7E7E7E]// then 'halt' - do nothing![/color]   }      [color=#7E7E7E]// Lets tell the user about what we found[/color]   putstring([color=#006699]"Using partition "[/color]);   [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](part, [color=#006699]DEC[/color]);   putstring([color=#006699]", type is FAT"[/color]);   [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]println[/color](vol.fatType(),[color=#006699]DEC[/color]); [color=#7E7E7E]// FAT16 or FAT32?[/color]      [color=#7E7E7E]// Try to open the root directory[/color]   [color=#CC6600]if[/color] (!root.openRoot(vol)) {     putstring_nl([color=#006699]"Can't open root dir!"[/color]); [color=#7E7E7E]// Something went wrong,[/color]     [color=#CC6600]while[/color](1); [color=#7E7E7E]// then 'halt' - do nothing![/color]   }      [color=#7E7E7E]// Whew! We got past the tough parts.[/color]   putstring_nl([color=#006699]"Ready!"[/color]); }

[color=#CC6600]void[/color] playcomplete([color=#CC6600]char[/color] good) {   [color=#7E7E7E]// call our helper to find and play this name[/color]   playfile([color=#006699]"GOOD.WAV"[/color]);   [color=#CC6600]while[/color] (wave.isplaying) {   [color=#7E7E7E]// do nothing while its playing[/color]   }   [color=#7E7E7E]// now its done playing[/color] }


[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]() {   [color=#7E7E7E]//putstring("."); // uncomment this to see if the loop isnt running [/color]        [color=#CC6600]switch[/color] (check_switches()) { [color=#7E7E7E]//this is the loop which cycles the arnold sounds based[/color]     [color=#CC6600]case[/color] 1: [color=#7E7E7E]//on which switch you connect to.[/color]       playcomplete([color=#006699]"STOP.WAV"[/color]);       [color=#CC6600]break[/color];     [color=#CC6600]case[/color] 2:       playcomplete([color=#006699]"SOB.WAV"[/color]);       [color=#CC6600]break[/color];     [color=#CC6600]case[/color] 3:       playcomplete([color=#006699]"DONT.WAV"[/color]);       [color=#CC6600]break[/color];     [color=#CC6600]case[/color] 4:       playcomplete([color=#006699]"LACK.WAV"[/color]);       [color=#CC6600]break[/color];     [color=#CC6600]case[/color] 5:       playcomplete([color=#006699]"FIST.WAV"[/color]);   } }

[color=#CC6600]byte[/color] check_switches() {   [color=#CC6600]static[/color] [color=#CC6600]byte[/color] previous[6];   [color=#CC6600]static[/color] [color=#CC6600]long[/color] time[6];   [color=#CC6600]byte[/color] reading;   [color=#CC6600]byte[/color] pressed;   [color=#CC6600]byte[/color] index;   pressed = 0;

  [color=#CC6600]for[/color] ([color=#CC6600]byte[/color] index = 0; index < 6; ++index) {     reading = [color=#CC6600]digitalRead[/color](14 + index);     [color=#CC6600]if[/color] (reading == [color=#006699]LOW[/color] && previous[index] == [color=#006699]HIGH[/color] && [color=#CC6600]millis[/color]() - time[index] > DEBOUNCE)     {       [color=#7E7E7E]// switch pressed[/color]       time[index] = [color=#CC6600]millis[/color]();       pressed = index + 1;       [color=#CC6600]break[/color];     }     previous[index] = reading;   }   [color=#7E7E7E]// return switch number (1 - 6)[/color]   [color=#CC6600]return[/color] (pressed); }


[color=#7E7E7E]// Plays a full file from beginning to end with no pause.[/color] [color=#CC6600]void[/color] playcomplete([color=#CC6600]char[/color] *name) {   [color=#7E7E7E]// call our helper to find and play this name[/color]   playfile(name);   [color=#CC6600]while[/color] (wave.isplaying) {   [color=#7E7E7E]// do nothing while its playing[/color]   }   [color=#7E7E7E]// now its done playing[/color] }

[color=#CC6600]void[/color] playfile([color=#CC6600]char[/color] *name) {   [color=#7E7E7E]// see if the wave object is currently doing something[/color]   [color=#CC6600]if[/color] (wave.isplaying) {[color=#7E7E7E]// already playing something, so stop it![/color]     wave.[color=#CC6600]stop[/color](); [color=#7E7E7E]// stop it[/color]   }   [color=#7E7E7E]// look in the root directory and open the file[/color]   [color=#CC6600]if[/color] (!f.open(root, name)) {     putstring([color=#006699]"Couldn't open file "[/color]); [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](name); [color=#CC6600]return[/color];   }   [color=#7E7E7E]// OK read the file and turn it into a wave object[/color]   [color=#CC6600]if[/color] (!wave.create(f)) {     putstring_nl([color=#006699]"Not a valid WAV"[/color]); [color=#CC6600]return[/color];   }      [color=#7E7E7E]// ok time to play! start playback[/color]   wave.play(); }

[/quote]