mirror of
https://github.com/ShikyC/Taiko-Drum-Controller-Arduino.git
synced 2024-11-12 00:50:46 +01:00
Added files via upload
This commit is contained in:
parent
61e729ff1d
commit
4be4b54a3a
@ -18,12 +18,13 @@
|
|||||||
#define POWER_CACHE_LENGTH 3
|
#define POWER_CACHE_LENGTH 3
|
||||||
|
|
||||||
// _THRES must be less than 2^32 = 4294967296 = 4.29e9
|
// _THRES must be less than 2^32 = 4294967296 = 4.29e9
|
||||||
#define LIGHT_THRES 3000000
|
#define LIGHT_THRES 2500000
|
||||||
#define HEAVY_THRES 10000000
|
#define HEAVY_THRES 5000000
|
||||||
|
|
||||||
#include <Keyboard.h>
|
#include <Keyboard.h>
|
||||||
|
|
||||||
int channelSample [CHANNELS];
|
int channelSample [CHANNELS];
|
||||||
|
int lastChannelSample [CHANNELS];
|
||||||
int sampleCache [CHANNELS][SAMPLE_CACHE_LENGTH];
|
int sampleCache [CHANNELS][SAMPLE_CACHE_LENGTH];
|
||||||
short int sampleCacheIndex [CHANNELS];
|
short int sampleCacheIndex [CHANNELS];
|
||||||
|
|
||||||
@ -47,6 +48,7 @@ void setup() {
|
|||||||
}
|
}
|
||||||
powerCacheIndex [i] = POWER_CACHE_LENGTH - 1;
|
powerCacheIndex [i] = POWER_CACHE_LENGTH - 1;
|
||||||
power [i] = 0;
|
power [i] = 0;
|
||||||
|
lastChannelSample [i] = 0;
|
||||||
triggered [i] = false;
|
triggered [i] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,40 +61,16 @@ void loop() {
|
|||||||
channelSample[2] = analogRead (A2); // L kat
|
channelSample[2] = analogRead (A2); // L kat
|
||||||
channelSample[3] = analogRead (A3); // R kat
|
channelSample[3] = analogRead (A3); // R kat
|
||||||
|
|
||||||
// Cache Operation
|
|
||||||
//
|
|
||||||
// Init status: [ 0 ] [ 1 ] [ 2 ] ... [n-3] [n-2] [n-1]
|
|
||||||
// |
|
|
||||||
// Pointer
|
|
||||||
//---------------------------------------------------------------
|
|
||||||
// Loop 0: [NEW] [ 1 ] [ 2 ] ... [n-3] [NEW] [n-1]
|
|
||||||
// | |
|
|
||||||
// Pointer Newest Diff
|
|
||||||
//---------------------------------------------------------------
|
|
||||||
// Loop 1: [ 0 ] [NEW] [ 2 ] ... [n-3] [n-2] [NEW]
|
|
||||||
// | | |
|
|
||||||
// Last sample Pointer Newest Diff
|
|
||||||
//---------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ...
|
|
||||||
// Pointer + 1: oldest differentiated sample
|
|
||||||
// Pointer : newest sample (original value from the analog port) <----
|
|
||||||
// Pointer - 1: last sample (original value from the analog port)
|
|
||||||
// Pointer - 2: newest differentiated sample
|
|
||||||
// Pointer - 3: last differentiated sample
|
|
||||||
// ...
|
|
||||||
|
|
||||||
for (short int i = 0; i < CHANNELS; i++) {
|
for (short int i = 0; i < CHANNELS; i++) {
|
||||||
|
|
||||||
sampleCacheIndex [i] = (sampleCacheIndex [i] + 1) % SAMPLE_CACHE_LENGTH;
|
sampleCacheIndex [i] = (sampleCacheIndex [i] + 1) % SAMPLE_CACHE_LENGTH;
|
||||||
|
|
||||||
sampleCache [i][sampleCacheIndex [i]] = channelSample [i];
|
sampleCache [i][sampleCacheIndex [i]] = channelSample [i] - lastChannelSample [i];
|
||||||
sampleCache [i][(sampleCacheIndex [i] - 2) % SAMPLE_CACHE_LENGTH] = channelSample [i] - sampleCache [i][(sampleCacheIndex [i] - 1) % SAMPLE_CACHE_LENGTH];
|
|
||||||
|
|
||||||
long int tempInt;
|
long int tempInt;
|
||||||
tempInt = sampleCache [i][(sampleCacheIndex [i] + 1) % SAMPLE_CACHE_LENGTH];
|
tempInt = sampleCache [i][(sampleCacheIndex [i] + 1) % SAMPLE_CACHE_LENGTH];
|
||||||
power [i] -= tempInt * tempInt;
|
power [i] -= tempInt * tempInt;
|
||||||
tempInt = sampleCache [i][(sampleCacheIndex [i] - 2) % SAMPLE_CACHE_LENGTH];
|
tempInt = sampleCache [i][sampleCacheIndex [i]];
|
||||||
power [i] += tempInt * tempInt;
|
power [i] += tempInt * tempInt;
|
||||||
|
|
||||||
if (power [i] < LIGHT_THRES) {
|
if (power [i] < LIGHT_THRES) {
|
||||||
@ -102,9 +80,11 @@ void loop() {
|
|||||||
powerCacheIndex [i] = (powerCacheIndex [i] + 1 ) % POWER_CACHE_LENGTH;
|
powerCacheIndex [i] = (powerCacheIndex [i] + 1 ) % POWER_CACHE_LENGTH;
|
||||||
powerCache [i][powerCacheIndex [i]] = power [i];
|
powerCache [i][powerCacheIndex [i]] = power [i];
|
||||||
|
|
||||||
|
lastChannelSample [i] = channelSample [i];
|
||||||
|
|
||||||
for (short int j = 0; j < POWER_CACHE_LENGTH - 1; j++){
|
for (short int j = 0; j < POWER_CACHE_LENGTH - 1; j++){
|
||||||
if (!triggered) {
|
if (!triggered) {
|
||||||
if (powerCache [i][(powerCacheIndex [i] + j) % POWER_CACHE_LENGTH] > powerCache [i][(powerCacheIndex [i] + j - 1) % POWER_CACHE_LENGTH] || j != POWER_CACHE_LENGTH - 2) {
|
if (powerCache [i][(powerCacheIndex [i] + j + 1) % POWER_CACHE_LENGTH] > powerCache [i][(powerCacheIndex [i] + j) % POWER_CACHE_LENGTH] || j != POWER_CACHE_LENGTH - 2) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
#if MODE_JIRO
|
#if MODE_JIRO
|
||||||
@ -139,7 +119,7 @@ void loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the end of each channel
|
// This is the end of each channel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user