KIK01 Proto 08
Dependencies: AverageMCP3008 VoltageMonitor mbed-rtos mbed mcp3008
Fork of KIK01_Proto07 by
Diff: main.cpp
- Revision:
- 36:3543a352b9d4
- Parent:
- 35:05798de92fb5
- Child:
- 37:85eb8e38cac8
--- a/main.cpp Wed Dec 20 19:53:57 2017 +0000 +++ b/main.cpp Sat Dec 23 09:26:45 2017 +0000 @@ -23,8 +23,10 @@ #include "VoltageMonitor.h" #define PIN_CHECK (1) +#define LED_SYNCOUT_BLINK (1) + #define TITLE_STR1 ("KIK01 Kick Machine Proto08") -#define TITLE_STR2 ("20171221") +#define TITLE_STR2 ("20171223") #define PI_F (3.1415926f) @@ -41,13 +43,16 @@ #define PM_LoThreshold (2.3f) #define PM_HiThreshold (2.7f) +#define LED_BEAT_BLINK_CYCLE (0.15f) +#define LED_SYNCIN_BLINK_CYCLE (0.04f) +#define LED_SYNCOUT_BLINK_CYCLE (0.04f) + // LEDs -DigitalOut LedPower(PC_5); +DigitalOut LedPower(PB_2); DigitalOut LedBeat(PA_12); DigitalOut LedSyncIn(PA_11); DigitalOut LedSyncOut(PB_12); - // Envelope Output AnalogOut Dac1(PA_4); AnalogOut Dac2(PA_5); @@ -76,9 +81,9 @@ InterruptIn SyncIn(PC_11); // Check pins -DigitalOut Dout1(PB_9); -DigitalOut Dout2(PB_8); -DigitalOut Dout3(PB_6); +DigitalOut Dout1(D14); +DigitalOut Dout2(D15); +DigitalOut Dout3(D2); EnvelopeAR envelopeFrequency(5, 300, 880.0f, 120.0f, 40.0f, 0.36f, 0.1f); EnvelopeAR envelopeAmplitude(50, 200, 0.99f, 1.0f, 0.0f); @@ -88,6 +93,12 @@ EnvelopeParam amplitudeParam; EnvelopeParam noiseAmplitudeParam; +Timeout timeoutLedBeat; +Timeout timeoutLedSyncIn; +#if (LED_SYNCOUT_BLINK) +Timeout timeoutLedSyncOut; +#endif + volatile int ticks; volatile float frequency; volatile float amplitude; @@ -97,6 +108,31 @@ volatile int envelopeLength; volatile int stepLength; +//----------------------------------------------------------------------------- +// Callback Functions +//----------------------------------------------------------------------------- + +void ledBeatAtTimeout() +{ + LedBeat = 0; +} + +void ledSyncInAtTimeout() +{ + LedSyncIn = 0; +} + +#if (LED_SYNCOUT_BLINK) +void ledSyncOutAtTimeout() +{ + LedSyncOut = 0; +} +#endif + +//----------------------------------------------------------------------------- +// Functions +//----------------------------------------------------------------------------- + void AD8402Write(uint8_t address, uint8_t value) { #if (PIN_CHECK) @@ -151,7 +187,10 @@ // Output Sync Signal per steps if (ticks % stepLength == 0) { SyncOut = 1; - LedSyncOut = !LedSyncOut; +#if (LED_SYNCOUT_BLINK) + LedSyncOut = 1; + timeoutLedSyncOut.attach(&ledSyncOutAtTimeout, LED_SYNCOUT_BLINK_CYCLE); +#endif } // set envelope parameters @@ -170,7 +209,8 @@ ticks++; if (ticks >= envelopeLength) { ticks = 0; - LedBeat = !LedBeat; + LedBeat = 1; + timeoutLedBeat.attach(&ledBeatAtTimeout, LED_BEAT_BLINK_CYCLE); } // Output SyncSignal @@ -215,7 +255,8 @@ void syncInFunction() { ticks = 0; - LedSyncIn = !LedSyncIn; + LedSyncIn = 1; + timeoutLedSyncIn.attach(&ledSyncInAtTimeout, LED_SYNCIN_BLINK_CYCLE); } void LedsCheck(int n, int wait) @@ -248,6 +289,8 @@ SpiMAdc.format(8, 0); SpiMAdc.frequency(MCP3008_SPI_SPEED); + + SyncIn.mode(PullDown); frequency = 100.0f; amplitude = 1.0f;