KIK 01 Prototype 05
Dependencies: AverageMCP3008 mbed-rtos mbed mcp3008
Fork of KIK01_Proto03 by
Diff: main.cpp
- Revision:
- 13:43a43da257e3
- Parent:
- 12:5b498285d121
- Child:
- 14:8e96f97e261b
--- a/main.cpp Tue Jun 06 15:31:41 2017 +0000 +++ b/main.cpp Wed Jun 21 00:14:49 2017 +0000 @@ -2,41 +2,34 @@ * KIK01 * Kick Machine * + * 2017.06.19 Proto02 * 2017.06.04 created. * */ #include "mbed.h" #include "rtos.h" +#include "mcp3008.h" #define UART_TRACE (1) #define PIN_CHECK (1) #define TITLE_STR1 ("KIK01 Kick Machine") -#define TITLE_STR2 ("20170606") +#define TITLE_STR2 ("20170621") #define PI_F (3.1415926f) -#define SAMPLING_RATE (96000) +#define SAMPLING_RATE (48000) #define SAMPLING_PERIOD (1.0f/SAMPLING_RATE) -#define ENVELOPE_UPDATE_RATE (32000) - -AnalogOut Dac1(PA_5); +#define ENVELOPE_UPDATE_RATE (48000) -AnalogIn Ain0(PA_0); -AnalogIn Ain1(PA_1); -AnalogIn Ain2(PA_4); -AnalogIn Ain3(PB_0); -AnalogIn Ain4(PC_1); -AnalogIn Ain5(PC_0); -AnalogIn Ain6(PC_2); -AnalogIn Ain7(PC_3); +AnalogOut Dac1(PA_4); -AnalogIn Ain8(PC_4); -AnalogIn Ain9(PB_1); -AnalogIn Ain10(PC_5); -AnalogIn Ain11(PA_6); +SPI spiM(SPI_MOSI, SPI_MISO, SPI_SCK); +MCP3008 Adc0(spiM, D9); +MCP3008 Adc1(spiM, D10); DigitalOut Dout0(PA_10); DigitalOut Dout1(PB_3); +DigitalOut Dout2(PB_5); class EnvelopeAR { @@ -239,30 +232,30 @@ void setParams() { - bpm = Ain0.read() * 180.0f + 60.0f; + bpm = Adc0.read_input(7) * 180.0f + 60.0f; envelopeLength = 60 * ENVELOPE_UPDATE_RATE / bpm; - amplitudeParam.attack = Ain1.read() * envelopeLength; - amplitudeParam.release = Ain2.read() * envelopeLength; - amplitudeParam.v0 = Ain3.read(); + amplitudeParam.attack = Adc0.read_input(0) * envelopeLength; + amplitudeParam.release = Adc0.read_input(1) * envelopeLength; + amplitudeParam.v0 = Adc0.read_input(4); amplitudeParam.v1 = 1.0f; amplitudeParam.v2 = 0.0f; amplitudeParam.attackTauRatio = 0.36f; - amplitudeParam.releaseTauRatio = Ain4.read() + 0.01f; + amplitudeParam.releaseTauRatio = Adc0.read_input(3) + 0.01f; - frequencyParam.attack = Ain8.read() * envelopeLength * 0.1f; - frequencyParam.release = Ain11.read() * envelopeLength + 1; - frequencyParam.v0 = Ain5.read() * 4000.0f; - frequencyParam.v1 = Ain6.read() * 400.0f; - frequencyParam.v2 = Ain7.read() * 400.0f; - frequencyParam.attackTauRatio = Ain9.read() + 0.01f; - frequencyParam.releaseTauRatio = Ain10.read() + 0.01f; + frequencyParam.attack = Adc1.read_input(0) * envelopeLength * 0.1f; + frequencyParam.release = Adc1.read_input(1) * envelopeLength + 1; + frequencyParam.v0 = Adc1.read_input(4) * 4000.0f; + frequencyParam.v1 = Adc1.read_input(5) * 400.0f; + frequencyParam.v2 = Adc1.read_input(6) * 400.0f; + frequencyParam.attackTauRatio = Adc1.read_input(2) + 0.01f; + frequencyParam.releaseTauRatio = Adc1.read_input(3) + 0.01f; } int main() { printf("%s %s\r\n", TITLE_STR1, TITLE_STR2); - + frequency = 1000.0f; phiDelta = 2.0f * frequency / SAMPLING_RATE; amplitude = 1.0f; @@ -277,7 +270,13 @@ samplingTicker.attach(&update, SAMPLING_PERIOD); for (;;) { +#if (PIN_CHECK) + Dout2 = 1; +#endif setParams(); +#if (PIN_CHECK) + Dout2 = 0; +#endif #if UART_TRACE printf("%.1f\t%d\t", bpm, envelopeLength); @@ -291,6 +290,6 @@ printf("%.2f\t%.2f\r\n", frequencyParam.attackTauRatio, frequencyParam.releaseTauRatio); #endif - Thread::wait(100); + Thread::wait(1); } }