调参数肝爆了,暂时先摸了
This commit is contained in:
parent
05196e2cbc
commit
9209d75058
@ -14,17 +14,17 @@
|
||||
|
||||
#define CHANNELS 2
|
||||
|
||||
#define SAMPLE_CACHE_LENGTH 5
|
||||
#define SAMPLE_CACHE_LENGTH 10
|
||||
|
||||
#define DON_SILENCE_THRES 5e3
|
||||
#define DON_LIGHT_THRES 5e4
|
||||
#define DON_SILENCE_THRES 1e4
|
||||
#define DON_LIGHT_THRES 3e4
|
||||
#define DON_HEAVY_THRES 1e5
|
||||
|
||||
#define KAT_SILENCE_THRES 2e3
|
||||
#define KAT_SILENCE_THRES 4e3
|
||||
#define KAT_LIGHT_THRES 5e3
|
||||
#define KAT_HEAVY_THRES 1e4
|
||||
|
||||
//#define FORCED_PERIOD 700
|
||||
#define FORCED_FREQ 1000
|
||||
|
||||
#include "cache.h"
|
||||
|
||||
@ -34,7 +34,7 @@ float channelSample[CHANNELS];
|
||||
Cache <float, SAMPLE_CACHE_LENGTH> sampleCache[CHANNELS];
|
||||
float power[CHANNELS];
|
||||
|
||||
bool triggered [CHANNELS];
|
||||
bool triggered;
|
||||
float light_thres[] = {DON_LIGHT_THRES, KAT_LIGHT_THRES};
|
||||
float heavy_thres[] = {DON_HEAVY_THRES, KAT_HEAVY_THRES};
|
||||
float silence_thres[] = {DON_SILENCE_THRES, KAT_SILENCE_THRES};
|
||||
@ -42,7 +42,7 @@ float silence_thres[] = {DON_SILENCE_THRES, KAT_SILENCE_THRES};
|
||||
int input_pins[] = {A0, A1}; // Don, Kat
|
||||
int output_pins[] = {A2, A3, A4, A5}; // Left Don, Left Kat, Right Don, Right Kat
|
||||
|
||||
String debug_output[] = {"DON", "KAT"};
|
||||
String debug_output[] = {"D", "K"};
|
||||
|
||||
void setup() {
|
||||
pinMode(A2, OUTPUT);
|
||||
@ -50,11 +50,10 @@ void setup() {
|
||||
pinMode(A4, OUTPUT);
|
||||
pinMode(A5, OUTPUT);
|
||||
Serial.begin (115200);
|
||||
// analogReference (INTERNAL);
|
||||
for (short int i = 0; i < CHANNELS; i++) {
|
||||
power [i] = 0;
|
||||
triggered [i] = false;
|
||||
power [i] = 0;
|
||||
}
|
||||
triggered = false;
|
||||
lastTime = 0;
|
||||
}
|
||||
|
||||
@ -62,38 +61,44 @@ void loop() {
|
||||
lastTime = micros ();
|
||||
for (short int i = 0; i < CHANNELS; i++) {
|
||||
channelSample[i] = analogRead(input_pins[i]);
|
||||
sampleCache[i].put(channelSample [i]);
|
||||
sampleCache[i].put(channelSample[i]);
|
||||
|
||||
long int tempInt;
|
||||
tempInt = sampleCache[i].get(1);
|
||||
long int tempInt = sampleCache[i].get(1);
|
||||
power[i] -= tempInt * tempInt;
|
||||
tempInt = sampleCache[i].get();
|
||||
power[i] += tempInt * tempInt;
|
||||
|
||||
if (power[i] < silence_thres[i]) {
|
||||
digitalWrite(output_pins[i], HIGH);
|
||||
digitalWrite(output_pins[i] + 2, HIGH);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
triggered[i] = false;
|
||||
} else if (power[i] > light_thres[i]) {
|
||||
if (!triggered [i]) {
|
||||
|
||||
if (power[i] > light_thres[i]) {
|
||||
if (!triggered) {
|
||||
digitalWrite(output_pins[i], LOW);
|
||||
if (power[i] >= heavy_thres[i]) {
|
||||
digitalWrite(output_pins[i] + 2, LOW);
|
||||
}
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
// Serial.println(debug_output[i]);
|
||||
}
|
||||
triggered[i] = true;
|
||||
if (i == 0) {
|
||||
triggered[1] = true;
|
||||
break;
|
||||
Serial.println(debug_output[i]);
|
||||
}
|
||||
triggered = true;
|
||||
}
|
||||
}
|
||||
Serial.print(power[0]);
|
||||
Serial.print("\t");
|
||||
Serial.println(power[1]);
|
||||
|
||||
for (short int i = 0; i < CHANNELS; i++) {
|
||||
triggered = false;
|
||||
digitalWrite(output_pins[i], HIGH);
|
||||
digitalWrite(output_pins[i] + 2, HIGH);
|
||||
if (power[i] > silence_thres[i]) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
triggered = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Serial.println(power[0]);
|
||||
float delayTime = 1e6 / FORCED_FREQ - (micros() - lastTime);
|
||||
if (delayTime > 0) {
|
||||
longMicroDelay(delayTime);
|
||||
} else {
|
||||
// digitalWrite(LED_BUILTIN, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
void longMicroDelay (float microTime) {
|
||||
|
Loading…
Reference in New Issue
Block a user