90 lines
1.8 KiB
Arduino
90 lines
1.8 KiB
Arduino
|
|
#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
|
||
|
|
|
||
|
|
}
|
||
|
|
|