HAHA! commit
This commit is contained in:
Executable
+88
@@ -0,0 +1,88 @@
|
||||
#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; }
|
||||
|
||||
Executable
+76
@@ -0,0 +1,76 @@
|
||||
|
||||
namespace eponge {
|
||||
|
||||
int raw0 = 0;
|
||||
int ema0 = 0;
|
||||
ExpMovAvg exmoav(&raw0, &ema0);
|
||||
|
||||
MinMaxLerp minmax(&ema0, 50, 800, 10000, 1000);
|
||||
|
||||
SpringMassDamper spring0(10.0, 19.0, 7.0);
|
||||
SpringMassDamper spring1(10.0, 19.0, 7.0);
|
||||
|
||||
}
|
||||
|
||||
using namespace eponge;
|
||||
|
||||
machine_template void MachineStates::enter<BBBB>() {
|
||||
|
||||
Serial.println("enter BBBB");
|
||||
|
||||
FluteEx.init();
|
||||
|
||||
usbMIDI.setHandleNoteOff(OnNoteOff);
|
||||
usbMIDI.setHandleNoteOn(OnNoteOn);
|
||||
usbMIDI.setHandleControlChange(OnControlChange);
|
||||
|
||||
Music.getPreset(15);
|
||||
|
||||
// Music.setGain1(1.0);
|
||||
// Music.setGain2(1.0);
|
||||
// Music.setGain3(1.0); // 1.0 for 3 oscs
|
||||
//
|
||||
// Music.setWaveform1(SINE);
|
||||
// Music.setWaveform2(SINE);
|
||||
// Music.setWaveform3(SINE);
|
||||
|
||||
// eponge::raw0 = 0;
|
||||
// eponge::ema0 = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
machine_template void MachineStates::exit<BBBB>() { Serial.println("exit BBBB"); }
|
||||
|
||||
machine_template void MachineStates::tick<BBBB>() {
|
||||
|
||||
eponge::raw0 = analogRead(A1); // pot 0
|
||||
eponge::exmoav.calculate();
|
||||
eponge::minmax.lerp_min_max();
|
||||
|
||||
int pos0 = eponge::spring0.position(eponge::ema0);
|
||||
int pos1 = eponge::spring1.position(pos0);
|
||||
|
||||
int minf = FluteEx.luxA();
|
||||
//int minf = analogRead(A9); // pot2
|
||||
minf = map(minf, 0, 1023, 25, 75);
|
||||
|
||||
int maxf = FluteEx.luxB();
|
||||
// int maxf = analogRead(A2); // pot1
|
||||
maxf = map(maxf, 0, 1023, 75, 125);
|
||||
|
||||
int f0 = map(eponge::ema0, 0, 1023, minf, maxf);
|
||||
Music.setFrequency1(f0);
|
||||
|
||||
int f1 = map(pos0, 0, 1023, minf, maxf);
|
||||
Music.setFrequency2(f1);
|
||||
|
||||
int f2 = map(pos1, 0, 1023, minf, maxf);
|
||||
Music.setFrequency3(f2);
|
||||
|
||||
usbMIDI.read();
|
||||
|
||||
}
|
||||
|
||||
machine_template int MachineStates::event<BBBB>() { return AAAA; }
|
||||
|
||||
Executable
+89
@@ -0,0 +1,89 @@
|
||||
#define MIDI_CHANNEL 1
|
||||
|
||||
#include <EEPROM.h>
|
||||
#include <spi4teensy3.h>
|
||||
#include <Mcp4251.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_TCS34725.h>
|
||||
|
||||
#include <Haarnet.h>
|
||||
#include <HaarnetExtensionFlute.h>
|
||||
|
||||
#include <ExpMovAvg.h>
|
||||
#include <MinMaxLerp.h>
|
||||
#include <SpringMassDamper.h>
|
||||
|
||||
#define PRINTLN(x,y) Serial.print(x); Serial.println(y);
|
||||
|
||||
|
||||
/////////// include FSM lib
|
||||
#include <FSM.h>
|
||||
#include <MachineStates.h>
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// STATE MACHINE DEF
|
||||
//------------------------------------------------------------
|
||||
|
||||
// list of states
|
||||
enum States { BBBB, AAAA };
|
||||
|
||||
class LaMachine : public MachineStates {
|
||||
public:
|
||||
typedef LIST2(BBBB, AAAA) StateList;
|
||||
};
|
||||
|
||||
StateMachine<LaMachine>* sm;
|
||||
LaMachine ms;
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// TIMER DEF
|
||||
//------------------------------------------------------------
|
||||
|
||||
|
||||
#define one_sec 1000000 // IntervalTimer is in microseconds
|
||||
#define timeout 10 * one_sec * 60
|
||||
IntervalTimer timer;
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// USUAL SUSPECTS
|
||||
//------------------------------------------------------------
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("starts");
|
||||
|
||||
Music.init();
|
||||
|
||||
sm = new StateMachine<LaMachine>(ms);
|
||||
|
||||
timer.begin(transition, timeout);
|
||||
randomSeed(analogRead(A4));
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// delay(2000);
|
||||
// Serial.print("... - "); Serial.println(sm->state);
|
||||
sm->tick();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// TRANSITIONS DEF
|
||||
//------------------------------------------------------------
|
||||
|
||||
void transition() {
|
||||
sm->work();
|
||||
}
|
||||
|
||||
void transition_random() {
|
||||
|
||||
int r = random(0, 2);
|
||||
while(r == sm->state)
|
||||
r = random(0, 2);
|
||||
|
||||
Event ev = {r};
|
||||
sm->work(ev); // transition
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user