KIK01 Prototype 04

Dependencies:   mbed-rtos mbed mcp3008

Fork of KIK01_Proto03 by Ryo Od

Revision:
14:8e96f97e261b
Parent:
13:43a43da257e3
Child:
15:8f674acdac03
diff -r 43a43da257e3 -r 8e96f97e261b main.cpp
--- a/main.cpp	Wed Jun 21 00:14:49 2017 +0000
+++ b/main.cpp	Sun Jun 25 15:38:44 2017 +0000
@@ -14,7 +14,7 @@
 #define UART_TRACE      (1)
 #define PIN_CHECK       (1)
 #define TITLE_STR1      ("KIK01 Kick Machine")
-#define TITLE_STR2      ("20170621")
+#define TITLE_STR2      ("20170625")
 
 #define PI_F            (3.1415926f)
 #define SAMPLING_RATE   (48000)
@@ -27,9 +27,13 @@
 MCP3008 Adc0(spiM, D9);
 MCP3008 Adc1(spiM, D10);
 
-DigitalOut Dout0(PA_10);
-DigitalOut Dout1(PB_3);
-DigitalOut Dout2(PB_5);
+// Check pins
+DigitalOut Dout0(D2);
+DigitalOut Dout1(D3);
+DigitalOut Dout2(D4);
+
+// Sync
+DigitalOut SyncPin(D7);
 
 class EnvelopeAR
 {
@@ -162,6 +166,7 @@
 
 volatile float bpm;
 volatile int envelopeLength;
+volatile int stepLength;
 
 void generateWave()
 {
@@ -195,6 +200,12 @@
 #if (PIN_CHECK)
         Dout0 = 1;
 #endif
+    
+    // Output Sync Signal per steps
+    if (envelopeTicks % stepLength == 0) {
+        SyncPin = 1;
+    }
+    
     ticks++;
     if (ticks >= SAMPLING_RATE / ENVELOPE_UPDATE_RATE) {
 #if (PIN_CHECK)
@@ -225,6 +236,10 @@
 #endif
     }
     generateWave();
+    
+    // Output SyncSignal
+    SyncPin = 0;
+    
 #if (PIN_CHECK)
         Dout0 = 0;
 #endif
@@ -234,12 +249,13 @@
 {
     bpm = Adc0.read_input(7) * 180.0f + 60.0f;
     envelopeLength = 60 * ENVELOPE_UPDATE_RATE / bpm;
+    stepLength = envelopeLength / 4;
 
     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.v1 = Adc0.read_input(5);
+    amplitudeParam.v2 = Adc0.read_input(6);
     amplitudeParam.attackTauRatio = 0.36f;
     amplitudeParam.releaseTauRatio = Adc0.read_input(3) + 0.01f;