diff --git a/arduino_zauberstab/arduino_zauberstab.ino b/arduino_zauberstab/arduino_zauberstab.ino deleted file mode 100644 index 40c6a30..0000000 --- a/arduino_zauberstab/arduino_zauberstab.ino +++ /dev/null @@ -1,222 +0,0 @@ -#include - - -//lichterkette: PWM 2 -//mikrofon: A1 -#define LED_PIN 2 -#define NUM_LEDS 144 - - -#define SAMPLING_FREQUENCY_BP 40 // number of energy chunks per second -#define SAMPLING_FREQUENCY_CONTROL 1 // check number of times per second if the current band pass is the best one -#define Q 20. // quality factor of band pass filters -#define PI 3.1415926535897932384626433832795 -#define n_BP 30 //number of band pass filters - - -CRGB leds[NUM_LEDS]; - -unsigned long sampling_period_bp = 1000000L/SAMPLING_FREQUENCY_BP; -unsigned long sampling_period_control = 1000000L/SAMPLING_FREQUENCY_CONTROL; -double energy = 0; -unsigned long last_us_bp = 0L; -unsigned long last_us_control = 0L; - -float a0[n_BP]; -float a1[n_BP]; -float a2[n_BP]; -float b0[n_BP]; -//float b1[n_BP]; -float b2[n_BP]; - -float a[n_BP]; -float w0[n_BP]; - -float yy1[n_BP]; -float yy2[n_BP]; -float yy3[n_BP]; -float yy4[n_BP]; -float yy5[n_BP]; -float yy6[n_BP]; - -float u1[n_BP]; -float u2[n_BP]; -float y[n_BP]; -float y_fil[n_BP]; - -float angle; -float angle2; - -double energy_fil = 800.; - - -float pos_target = NUM_LEDS/2; -float pos_target_filtered = NUM_LEDS/2; - -float microphone_offset = 512; -long initial_time; - -int active = 15; -int candidate = 15; -int rounds = 0; - - - - -void setup() { - - Serial.begin(250000); - - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setMaxPowerInVoltsAndMilliamps(5, 300); - -// for(int i = 0; i < NUM_LEDS; i++) -// { int brightness = get_value(i, pos_target_filtered); -// leds[i].setRGB(brightness, brightness, brightness); } -// FastLED.show(); -// -// long sumsamples = 0; -// for(int j = 1; j<1000; j++) -// { -// int sample = analogRead(1); -// sumsamples += sample; -// delay(1); -// if(j==500) -// { -// sumsamples = 0; -// } -// } -// microphone_offset = sumsamples/500; - - - set_filter(); - initial_time = micros(); - - -} - -void set_filter() { - for(int i = 0; i < n_BP; i++) - { - float frequency = 1.75+i*(2.4-1.75)/n_BP; - w0[i] = 2.*PI*frequency/SAMPLING_FREQUENCY_BP; - a[i] = sin(w0[i]/(2.*Q)); - b0[i] = a[i]; - //b1[i] = 0; - b2[i] = -a[i]; - a0[i] = 1.+a[i]; - a1[i] = -2.*cos(w0[i]); - a2[i] = 1.-a[i]; - } -} - -int get_value(int pos, float pos0) { - if (abs(pos0-pos) > 20) { return 0; } - else { return (40-abs(pos0-pos)*2); } -} - -void loop() { - - int sample = int(analogRead(1) - microphone_offset); - energy += abs(sample)*abs(sample); - - if (micros() - last_us_bp > sampling_period_bp) - { - - Serial.println(sample); - - microphone_offset += (analogRead(1)-microphone_offset)*0.001; - - //Serial.println(microphone_offset); - - last_us_bp += sampling_period_bp; - energy_fil += (energy - energy_fil) * 0.01; - //Serial.println(energy); - for(int i = 0; i < n_BP; i++) - { - y[i] = (b0[i]/a0[i])*energy + 0. + (b2[i]/a0[i])*u2[i] - (a1[i]/a0[i])*yy1[i] - (a2[i]/a0[i])*yy2[i]; - u2[i] = u1[i]; - u1[i] = energy; - yy6[i] = yy5[i]; - yy5[i] = yy4[i]; - yy4[i] = yy3[i]; - yy3[i] = yy2[i]; - yy2[i] = yy1[i]; - yy1[i] = y[i]; - y_fil[i] += (abs(y[i]) - y_fil[i]) * 0.005; //linie der scheitelpunkte - } - - float delays = constrain( SAMPLING_FREQUENCY_BP * 0.25/(1.75+active*(2.4-1.75)/n_BP) , 4., 6.); - - float delayed = 0; - if (delays > 5) - {delayed = yy5[active]*(1-delays+5) + yy6[active]*(delays-5); } - else - {delayed = yy4[active]*(1-delays+4) + yy5[active]*(delays-4); } - - angle = atan2(delayed , y[active]); - - if (PI < abs(angle - angle2) && abs(angle - angle2) < 3*PI) - { angle2 = angle + 2*PI; } - else - { angle2 = angle; } - - pos_target = map(angle2, -PI, 3*PI, -0.3*NUM_LEDS, NUM_LEDS*1.5); - - if (pos_target > pos_target_filtered) - { pos_target_filtered += (pos_target - pos_target_filtered)*0.35; } - else - { pos_target_filtered = pos_target; } - -// Serial.print(y_fil[active]); -// Serial.print(","); -// Serial.println(y[active]); - - energy = 0; - - - - - for(int i = 0; i < NUM_LEDS; i++) - { - int brightness = get_value(i, pos_target_filtered); - - //leds[i].setRGB(brightness, brightness, brightness); - leds[i].setHSV( 160, (rounds == 6) ? 60 : 0, brightness); - } - FastLED.show(); - } - - if (micros() - last_us_control > sampling_period_control) - { - last_us_control += sampling_period_control; - int argmax = -1; - float valuemax = 0; - for(int i = 0; i < n_BP; i++) - { - if(y_fil[i] > valuemax) - { - valuemax = y_fil[i]; - argmax = i; - } - } - - if(argmax > -1) - { - if(argmax == candidate) - { - rounds ++; - } - else - { - rounds = 0; - candidate = argmax; - } - if(rounds > 6) - { - rounds = 0; - active = candidate; - } - } - } -} diff --git a/firmware/src/applications/beat_detect.cpp b/firmware/src/applications/beat_detect.cpp index 096ab09..6dc9b0a 100644 --- a/firmware/src/applications/beat_detect.cpp +++ b/firmware/src/applications/beat_detect.cpp @@ -107,11 +107,14 @@ void BeatDetectApp::deinit() void BeatDetectApp::loop() { float sample = get_sample(); + energy += std::abs(sample) * std::abs(sample); n_samples++; if (micros() - last_us_bp > sampling_period_bp) { + + n_samples = 0; last_us_bp = micros(); // energy_fil += (energy - energy_fil) * 0.01; @@ -131,6 +134,7 @@ void BeatDetectApp::loop() // scheitelpunkte } + float delays = constrain(SAMPLING_FREQUENCY_BP * 0.25 / (1.75 + active * (2.4 - 1.75) / n_BP), 4., 6.); @@ -146,6 +150,8 @@ void BeatDetectApp::loop() angle = atan2(delayed, y[active]); + + if (PI < abs(angle - angle2) && abs(angle - angle2) < 3 * PI) { angle2 = angle + 2 * PI; @@ -156,6 +162,9 @@ void BeatDetectApp::loop() } pos_target = map(angle2, -PI, 3 * PI, -0.3 * NUM_LEDS, NUM_LEDS * 1.5); + //pos_target = NUM_LEDS * (sin(angle2)+1)/2; + + if (pos_target > pos_target_filtered) { @@ -167,6 +176,7 @@ void BeatDetectApp::loop() pos_target_filtered = pos_target; } + energy = 0; for (int i = 0; i < NUM_LEDS; i++) diff --git a/firmware/src/applications/fft_detect.cpp b/firmware/src/applications/fft_detect.cpp index a81d48a..e831a44 100644 --- a/firmware/src/applications/fft_detect.cpp +++ b/firmware/src/applications/fft_detect.cpp @@ -107,6 +107,8 @@ void FftDetectApp::loop() yy2 = yy1; yy1 = y; y_fil = y_filter.update(std::abs(y), 0.005f); + + float delayed = yy5; @@ -154,6 +156,20 @@ void FftDetectApp::loop() if (sample_counter == N_SAMPLES) { + + float samplesum = 0.f; + for (int i = 0; i < N_SAMPLES;i++) + { + samplesum = samplesum + std::abs(samples[i]); + } + + float sampleavg = samplesum/N_SAMPLES; + + for (int i = 0; i < N_SAMPLES;i++) + { + samples[i] = samples[i] - sampleavg; + } + FFT::fft(samples, z, N_SAMPLES); float max = 0.f; @@ -161,21 +177,19 @@ void FftDetectApp::loop() for (int i = 20; i < 30; i++) { float v = std::abs(z[i]); + if (v > max) { max = v; pos = i; } - } + Serial.println(v); + } float frequency = 40.f/512.f*pos; set_filter(frequency); sample_counter = 0; - } - - - } diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index 4bebc2e..9d8b4ad 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -26,7 +26,7 @@ std::vector> apps = { std::ref(fackel_app), std::ref(fft_detect_app)}; -unsigned int current_app = 4; +unsigned int current_app = 0; unsigned int next_app; void setup() diff --git a/inventor/Assembly1.iam b/inventor/Assembly1.iam index 7ca6e4f..2935a8c 100644 Binary files a/inventor/Assembly1.iam and b/inventor/Assembly1.iam differ diff --git a/inventor/OldVersions/Assembly1.0007.iam b/inventor/OldVersions/Assembly1.0008.iam similarity index 91% rename from inventor/OldVersions/Assembly1.0007.iam rename to inventor/OldVersions/Assembly1.0008.iam index bae79bb..7ca6e4f 100644 Binary files a/inventor/OldVersions/Assembly1.0007.iam and b/inventor/OldVersions/Assembly1.0008.iam differ diff --git a/inventor/OldVersions/Spant2.0001.ipt b/inventor/OldVersions/Spant2.0001.ipt new file mode 100644 index 0000000..e19e037 Binary files /dev/null and b/inventor/OldVersions/Spant2.0001.ipt differ diff --git a/inventor/OldVersions/holz.0001.dwg b/inventor/OldVersions/holz.0001.dwg new file mode 100644 index 0000000..1f936cb Binary files /dev/null and b/inventor/OldVersions/holz.0001.dwg differ diff --git a/inventor/OldVersions/lower_centering_ring.0001.ipt b/inventor/OldVersions/lower_centering_ring.0001.ipt new file mode 100644 index 0000000..86a9e00 Binary files /dev/null and b/inventor/OldVersions/lower_centering_ring.0001.ipt differ diff --git a/inventor/OldVersions/top_centering_ring.0001.ipt b/inventor/OldVersions/top_centering_ring.0001.ipt deleted file mode 100644 index 74b8bfe..0000000 Binary files a/inventor/OldVersions/top_centering_ring.0001.ipt and /dev/null differ diff --git a/inventor/OldVersions/top_centering_ring.0003.ipt b/inventor/OldVersions/top_centering_ring.0003.ipt new file mode 100644 index 0000000..ef18a3b Binary files /dev/null and b/inventor/OldVersions/top_centering_ring.0003.ipt differ diff --git a/inventor/OldVersions/vase_v2._tom.0021.ipt b/inventor/OldVersions/vase_v2._tom.0021.ipt new file mode 100644 index 0000000..b764492 Binary files /dev/null and b/inventor/OldVersions/vase_v2._tom.0021.ipt differ diff --git a/inventor/Spant2.ipt b/inventor/Spant2.ipt index e19e037..2cfb239 100644 Binary files a/inventor/Spant2.ipt and b/inventor/Spant2.ipt differ diff --git a/inventor/boden.ipt b/inventor/boden.ipt new file mode 100644 index 0000000..fb0c029 Binary files /dev/null and b/inventor/boden.ipt differ diff --git a/inventor/holz.dwg b/inventor/holz.dwg new file mode 100644 index 0000000..d0b9932 Binary files /dev/null and b/inventor/holz.dwg differ diff --git a/inventor/holz.pdf b/inventor/holz.pdf new file mode 100644 index 0000000..8c9d474 Binary files /dev/null and b/inventor/holz.pdf differ diff --git a/inventor/lower_centering_ring.ipt b/inventor/lower_centering_ring.ipt index 86a9e00..c5542fd 100644 Binary files a/inventor/lower_centering_ring.ipt and b/inventor/lower_centering_ring.ipt differ diff --git a/inventor/top_center_ring.ipt b/inventor/top_center_ring.ipt deleted file mode 100644 index 94f108b..0000000 Binary files a/inventor/top_center_ring.ipt and /dev/null differ diff --git a/inventor/top_centering_ring.ipt b/inventor/top_centering_ring.ipt index 1d41db7..80f4a66 100644 Binary files a/inventor/top_centering_ring.ipt and b/inventor/top_centering_ring.ipt differ diff --git a/inventor/~holz.dwg.14084.tmp b/inventor/~holz.dwg.14084.tmp new file mode 100644 index 0000000..acaa5f7 Binary files /dev/null and b/inventor/~holz.dwg.14084.tmp differ