KIK 01 Prototype 05

Dependencies:   AverageMCP3008 mbed-rtos mbed mcp3008

Fork of KIK01_Proto03 by Ryo Od

Revision:
28:387c5a6d5206
Parent:
27:b07a55935230
Child:
29:947992b9904f
--- a/main.cpp	Thu Oct 19 06:36:10 2017 +0000
+++ b/main.cpp	Thu Oct 19 07:15:45 2017 +0000
@@ -13,6 +13,7 @@
 #include "mbed.h"
 #include "rtos.h"
 #include "mcp3008.h"
+#include "AverageMCP3008.h"
 #include "EnvelopeAR.h"
 
 #define UART_TRACE      (1)
@@ -43,6 +44,9 @@
 MCP3008 Adc1(&SpiMAdc, PB_10);
 MCP3008 Adc2(&SpiMAdc, PA_8);
 MCP3008 Adc3(&SpiMAdc, PA_9);
+AverageMCP3008 AvgAdc1(&Adc1, 8); 
+AverageMCP3008 AvgAdc2(&Adc2, 8); 
+AverageMCP3008 AvgAdc3(&Adc3, 8); 
 
 // Sync
 DigitalOut SyncPin(PA_10);
@@ -147,25 +151,25 @@
 
 void readParams()
 {
-    bpm = Adc1.read_input(7) * 180.0f + 60.0f;
+    bpm = AvgAdc1.read_input(7) * 180.0f + 60.0f;
     envelopeLength = 60 * ENVELOPE_UPDATE_RATE / bpm;
     stepLength = envelopeLength / 4;
 
-    amplitudeParam.attack = Adc1.read_input(0) * envelopeLength;
-    amplitudeParam.release = Adc1.read_input(1) * envelopeLength;
-    amplitudeParam.v0 = Adc1.read_input(4);
-    amplitudeParam.v1 = Adc1.read_input(5);
-    amplitudeParam.v2 = Adc1.read_input(6);
-    amplitudeParam.attackTauRatio = Adc1.read_input(2) + 0.01f;
-    amplitudeParam.releaseTauRatio = Adc1.read_input(3) + 0.01f;
+    amplitudeParam.attack = AvgAdc1.read_input(0) * envelopeLength;
+    amplitudeParam.release = AvgAdc1.read_input(1) * envelopeLength;
+    amplitudeParam.v0 = AvgAdc1.read_input(4);
+    amplitudeParam.v1 = AvgAdc1.read_input(5);
+    amplitudeParam.v2 = AvgAdc1.read_input(6);
+    amplitudeParam.attackTauRatio = AvgAdc1.read_input(2) + 0.01f;
+    amplitudeParam.releaseTauRatio = AvgAdc1.read_input(3) + 0.01f;
 
-    frequencyParam.attack = Adc2.read_input(0) * envelopeLength * 0.1f;
-    frequencyParam.release = Adc2.read_input(1) * envelopeLength + 1;
-    frequencyParam.v0 = Adc2.read_input(4) * 4000.0f;
-    frequencyParam.v1 = Adc2.read_input(5) * 400.0f;
-    frequencyParam.v2 = Adc2.read_input(6) * 400.0f;
-    frequencyParam.attackTauRatio = Adc2.read_input(2) + 0.01f;
-    frequencyParam.releaseTauRatio = Adc2.read_input(3) + 0.01f;
+    frequencyParam.attack = AvgAdc2.read_input(0) * envelopeLength * 0.1f;
+    frequencyParam.release = AvgAdc2.read_input(1) * envelopeLength + 1;
+    frequencyParam.v0 = AvgAdc2.read_input(4) * 4000.0f;
+    frequencyParam.v1 = AvgAdc2.read_input(5) * 400.0f;
+    frequencyParam.v2 = AvgAdc2.read_input(6) * 400.0f;
+    frequencyParam.attackTauRatio = AvgAdc2.read_input(2) + 0.01f;
+    frequencyParam.releaseTauRatio = AvgAdc2.read_input(3) + 0.01f;
 }
 
 int main()