See commit words
Dependencies: SDFileSystem_high_spi_freq mbed wave_player_pwm_and_dac
Revision 0:205c27289cf4, committed 2014-12-05
- Comitter:
- lenhardt
- Date:
- Fri Dec 05 02:34:45 2014 +0000
- Commit message:
- This is Wheel Beats working with ADC, playing through PWMout for a ; headphone/speaker audio jack when you hit the force sensitive resistor squares. Oh, and it reads it off an SD card at an spi frequency of 25MHz.
Changed in this revision
diff -r 000000000000 -r 205c27289cf4 SDFileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Fri Dec 05 02:34:45 2014 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/lenhardt/code/SDFileSystem_high_spi_freq/#a3fe24740f94
diff -r 000000000000 -r 205c27289cf4 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Dec 05 02:34:45 2014 +0000 @@ -0,0 +1,78 @@ +#include "mbed.h" +#include "SDFileSystem.h" +#include "wave_player.h" + +SPI spi(p11, p12, p13); // mosi(out), miso(in), sclk(clock) +DigitalOut cs(p14); // cs (the chip select signal) +Serial pc(USBTX, USBRX); // tx, rx ( the usb serial communication ) + +SDFileSystem sd(p5, p6, p7, p8, "sd"); +PwmOut PWMout(p21); +AnalogOut DACout(p18); +AnalogIn fsr(p15); +wave_player waver(&DACout,&PWMout); +FILE *wave_file; + +int main() { + // Setup the spi for 7 bit data, high steady state clock, + // second edge capture, with a 1MHz clock rate + spi.format(7,0); + spi.frequency(1000000); + + // Set PWMout period + PWMout.period(1.0/400000.0); + + // notify the user that we are starting with the ADC communication + pc.printf("Starting ADC interaction\n\n\n"); + + // lets just do this forever + while (1) { + + for (int i = 0 ; i < 2; i++){ + // Select the device by seting chip select low + cs = 0; + + // sending the 6 bits + 1 bit to ignore the null bit + // coming from the device, so the data that is sent is 1100000 + spi.write(0x60 + (i*4)); + + // now the device sends back the readings 12 bits, 7 bits at a time + uint8_t high = spi.write(0x00); + uint8_t low = spi.write(0x00); + + // shift out the right bits + low = ( high << 5 ) | (low >> 2); + high = high >> 3; + + // shift and or the result together + int value = ( high << 8 ) | low; + + // and voila we have the value and we can print it for the user + //pc.printf("sensor %d value = %u\n", i, value); + switch (i){ + case 0: + if (value > 200) { + pc.printf("\tX\r"); + wave_file=fopen("/sd/highhat.wav","r"); + waver.play(wave_file); + fclose(wave_file); + } + break; + case 1: + if (value > 200){ + pc.printf("\t\t\t\tX\r"); + wave_file=fopen("/sd/snare.wav","r"); + waver.play(wave_file); + fclose(wave_file); + } + break; + } + + // Deselect the device + cs = 1; + } + + // delay some time before reading again + wait_us(100); + } +} \ No newline at end of file
diff -r 000000000000 -r 205c27289cf4 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Dec 05 02:34:45 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file
diff -r 000000000000 -r 205c27289cf4 wave_player.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wave_player.lib Fri Dec 05 02:34:45 2014 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/lenhardt/code/wave_player_pwm_and_dac/#da5d90e12f27