New design init

This commit is contained in:
ShikyC 2017-11-21 17:34:09 -05:00
parent 49c3ee02aa
commit 3aa41ca472

View File

@ -1,126 +1,119 @@
/*************************************************************** /***************************************************************
* * * *
* Taiko Sanro - Arduino * * Taiko Sanro - Arduino *
* Support Arduino models with ATmega32u4 microprocessors * * Support Arduino models with ATmega32u4 microprocessors *
* * * *
* Shiky Chang Chris * * Shiky Chang Chris *
* zhangxunpx@gmail.com wisaly@gmail.com * * zhangxunpx@gmail.com wisaly@gmail.com *
* * * *
***************************************************************/ ***************************************************************/
// Compatibility with Taiko Jiro // New implementation using fast, stable and sensitive piezoelectric
#define MODE_JIRO 1 // ceramic sensors (the same sensors used in electirc drum kit).
// No longer need microphones.
#define MODE_DEBUG 0
#define MODE_DEBUG 0
#define CHANNELS 4
#define CHANNELS 2
// Caches for the soundwave and power
#define SAMPLE_CACHE_LENGTH 12 // Caches for the soundwave and power
#define POWER_CACHE_LENGTH 3 #define SAMPLE_CACHE_LENGTH 12
#define POWER_CACHE_LENGTH 3
// Light and heacy hit thresholds
#define LIGHT_THRES 5000 // Light and heacy hit thresholds
#define HEAVY_THRES 20000 #define LIGHT_THRES 5000
#define HEAVY_THRES 20000
// Forced sampling frequency
#define FORCED_FREQ 1000 // Forced sampling frequency
#define FORCED_FREQ 1000
#include <limits.h>
#include <Keyboard.h> #include "cache.h"
#include "cache.h"
unsigned long int lastTime;
#if MODE_JIRO
#define HEAVY_THRES LONG_MAX int channelSample [CHANNELS];
#endif int lastChannelSample [CHANNELS];
Cache <int, SAMPLE_CACHE_LENGTH> sampleCache [CHANNELS];
unsigned long int lastTime;
long int power [CHANNELS];
int channelSample [CHANNELS]; Cache <long int, POWER_CACHE_LENGTH> powerCache [CHANNELS];
int lastChannelSample [CHANNELS];
Cache <int, SAMPLE_CACHE_LENGTH> sampleCache [CHANNELS]; bool triggered [CHANNELS];
long int power [CHANNELS]; int pins[] = {A0, A1}; // Don, Kat
Cache <long int, POWER_CACHE_LENGTH> powerCache [CHANNELS];
void setup() {
bool triggered [CHANNELS]; Serial.begin (9600);
Keyboard.begin ();
int pins[] = {A0, A1, A2, A3}; // L don, R don, L kat, R kat analogReference (DEFAULT);
char lightKeys[] = {'g', 'h', 'f', 'j'}; for (short int i = 0; i < CHANNELS; i++) {
char heavyKeys[] = {'t', 'y', 'r', 'u'}; power [i] = 0;
lastChannelSample [i] = 0;
void setup() { triggered [i] = false;
Serial.begin (9600); }
Keyboard.begin (); lastTime = 0;
analogReference (DEFAULT); }
for (short int i = 0; i < CHANNELS; i++) {
power [i] = 0; void loop() {
lastChannelSample [i] = 0;
triggered [i] = false; for (short int i = 0; i < CHANNELS; i++) {
}
lastTime = 0; channelSample[i] = analogRead (pins [i]);
} sampleCache [i].put (channelSample [i] - lastChannelSample [i]);
void loop() { long int tempInt;
tempInt = sampleCache [i].get (1);
for (short int i = 0; i < CHANNELS; i++) { power [i] -= tempInt * tempInt;
tempInt = sampleCache [i].get ();
channelSample[i] = analogRead (pins [i]); power [i] += tempInt * tempInt;
sampleCache [i].put (channelSample [i] - lastChannelSample [i]); if (power [i] < LIGHT_THRES) {
power [i] = 0;
long int tempInt; }
tempInt = sampleCache [i].get (1);
power [i] -= tempInt * tempInt; powerCache [i].put (power [i]);
tempInt = sampleCache [i].get (); lastChannelSample [i] = channelSample [i];
power [i] += tempInt * tempInt; if (powerCache [i].get (1) == 0) {
if (power [i] < LIGHT_THRES) { triggered [i] = false;
power [i] = 0; }
}
if (!triggered [i]) {
powerCache [i].put (power [i]); for (short int j = 0; j < POWER_CACHE_LENGTH - 1; j++) {
lastChannelSample [i] = channelSample [i]; if (powerCache [i].get (j - 1) >= powerCache [i].get (j)) {
if (powerCache [i].get (1) == 0) { break;
triggered [i] = false; } else if (powerCache [i].get (1) >= HEAVY_THRES) {
} triggered [i] = true;
Keyboard.print (heavyKeys [i]);
if (!triggered [i]) { } else if (powerCache [i].get (1) >= LIGHT_THRES) {
for (short int j = 0; j < POWER_CACHE_LENGTH - 1; j++) { triggered [i] = true;
if (powerCache [i].get (j - 1) >= powerCache [i].get (j)) { Keyboard.print (lightKeys [i]);
break; }
} else if (powerCache [i].get (1) >= HEAVY_THRES) { }
triggered [i] = true; }
Keyboard.print (heavyKeys [i]);
} else if (powerCache [i].get (1) >= LIGHT_THRES) { #if MODE_DEBUG
triggered [i] = true; Serial.print (power [i]);
Keyboard.print (lightKeys [i]); Serial.print ("\t");
} #endif
}
} // End of each channel
}
#if MODE_DEBUG
Serial.print (power [i]); #if MODE_DEBUG
Serial.print ("\t"); Serial.print (50000);
#endif Serial.print ("\t");
Serial.print (0);
// End of each channel Serial.print ("\t");
}
Serial.println ("");
#if MODE_DEBUG #endif
Serial.print (50000);
Serial.print ("\t"); // Force the sample frequency to be less than 1000Hz
Serial.print (0); unsigned int frameTime = micros () - lastTime;
Serial.print ("\t"); lastTime = micros ();
if (frameTime < FORCED_FREQ) {
Serial.println (""); delayMicroseconds (FORCED_FREQ - frameTime);
#endif } else {
// Performance bottleneck;
// Force the sample frequency to be less than 1000Hz Serial.print ("Exception: forced frequency is too high for the microprocessor to catch up.");
unsigned int frameTime = micros () - lastTime; }
lastTime = micros (); }
if (frameTime < FORCED_FREQ) {
delayMicroseconds (FORCED_FREQ - frameTime);
} else {
// Performance bottleneck;
Serial.print ("Exception: forced frequency is too high for the microprocessor to catch up.");
}
}