89 lines
1.8 KiB
Arduino
89 lines
1.8 KiB
Arduino
|
|
#include <Haarnet.h>
|
||
|
|
|
||
|
|
namespace bizarre {
|
||
|
|
|
||
|
|
int raw0 = 0;
|
||
|
|
int ema0 = 0;
|
||
|
|
ExpMovAvg exmoav(&bizarre::raw0, &bizarre::ema0);
|
||
|
|
|
||
|
|
SpringMassDamper spring0(10.0, 19.0, 7.0);
|
||
|
|
SpringMassDamper spring1(10.0, 19.0, 7.0);
|
||
|
|
|
||
|
|
float r = 0;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
using namespace bizarre;
|
||
|
|
|
||
|
|
machine_template void MachineStates::enter<AAAA>() {
|
||
|
|
|
||
|
|
Serial.println("enter AAAA");
|
||
|
|
|
||
|
|
FluteEx.init();
|
||
|
|
|
||
|
|
pinMode(A0, INPUT);
|
||
|
|
|
||
|
|
usbMIDI.setHandleNoteOff(OnNoteOff);
|
||
|
|
usbMIDI.setHandleNoteOn(OnNoteOn);
|
||
|
|
usbMIDI.setHandleControlChange(OnControlChange);
|
||
|
|
|
||
|
|
Music.getPreset(12);
|
||
|
|
|
||
|
|
Music.setGain1(0.5);
|
||
|
|
Music.setGain2(0.5);
|
||
|
|
Music.setGain3(0.5);
|
||
|
|
|
||
|
|
Music.setWaveform1(SQUARE);
|
||
|
|
Music.setWaveform2(SINE);
|
||
|
|
Music.setWaveform3(SQUARE);
|
||
|
|
|
||
|
|
// bizarre::raw0 = 0;
|
||
|
|
// bizarre::ema0 = 0;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
machine_template void MachineStates::exit<AAAA>() { Serial.println("exit AAAA"); }
|
||
|
|
|
||
|
|
machine_template void MachineStates::tick<AAAA>() {
|
||
|
|
|
||
|
|
int memory_junk[4];
|
||
|
|
bizarre::raw0 = memory_junk[0] + memory_junk[1];// + memory_junk[2] + memory_junk[3];
|
||
|
|
|
||
|
|
bizarre::exmoav.calculate();
|
||
|
|
|
||
|
|
int pos0 = bizarre::spring0.position(bizarre::ema0);
|
||
|
|
int pos1 = bizarre::spring1.position(pos0);
|
||
|
|
|
||
|
|
int t = analogRead(A1);
|
||
|
|
t = map(t, 0, 1023, 2, 575);
|
||
|
|
//t = map(t, 0, 1023, 2, 75); -- great
|
||
|
|
delay(t);
|
||
|
|
|
||
|
|
r += 0.001;
|
||
|
|
|
||
|
|
int q = 20000;
|
||
|
|
int minf = 50, maxf = 20000;
|
||
|
|
|
||
|
|
float f0 = map(bizarre::ema0, -q, q, minf, maxf); //or
|
||
|
|
//float f0 = sin(r) * (float)(t*2);
|
||
|
|
Music.setFrequency1(f0);
|
||
|
|
|
||
|
|
// Serial.println(f0);
|
||
|
|
|
||
|
|
float f1 = map(pos0, -q, q, minf, maxf);
|
||
|
|
Music.setFrequency2(f1);
|
||
|
|
|
||
|
|
// Serial.println(f1);
|
||
|
|
|
||
|
|
float f2 = map(pos1, -q, q, minf, maxf);
|
||
|
|
Music.setFrequency3(f2);
|
||
|
|
|
||
|
|
// Serial.println(f2);
|
||
|
|
|
||
|
|
usbMIDI.read();
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
machine_template int MachineStates::event<AAAA>() { return BBBB; }
|
||
|
|
|