Difference between revisions of "Students/Ian Petrov"
Line 42: | Line 42: | ||
Code | Code | ||
---- | ---- | ||
− | // | + | [quote] |
− | // | + | [color=#7E7E7E]//Ian Petrov VIS147A Final[/color] |
− | # | + | [color=#7E7E7E]//code edited from Adafruit Wave Shield Site[/color] |
− | # | + | #include <FatReader.h> |
− | # | + | #include <SdReader.h> |
− | # | + | #include <avr/pgmspace.h> |
− | # | + | #include [color=#006699]"WaveUtil.h"[/color] |
+ | #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] | |
− | # | + | #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] |
− | int freeRam(void) | + | [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; | |
− | } | + | } |
− | void sdErrorCheck(void) | + | [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); | |
} | } | ||
− | void setup() { | + | [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]); | |
} | } | ||
− | void playcomplete(char good) { | + | [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] | |
} | } | ||
− | void loop() { | + | [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]); | |
− | + | } | |
} | } | ||
− | byte check_switches() | + | [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] |
− | void playcomplete(char *name) { | + | [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] | |
} | } | ||
− | void playfile(char *name) { | + | [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] |
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.
Portable Heater
Generator?
Air Conditioner
Cell Phone
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.
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.
Code
[quote] [color=#7E7E7E]//Ian Petrov VIS147A Final[/color] [color=#7E7E7E]//code edited from Adafruit Wave Shield Site[/color]
- include <FatReader.h>
- include <SdReader.h>
- include <avr/pgmspace.h>
- include [color=#006699]"WaveUtil.h"[/color]
- 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]
- 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]