/* http://arduinomidilib.fortyseveneffects.com/a00025.html */ #include "Structs.h" #include "MIDI.h" #include "midi_Defs.h" #include "midi_Message.h" #include "midi_Namespace.h" #include "midi_Settings.h" /** #include #include #include #include #include **/ //#define DEBUG #define MIN_SPEED 100 #define MAX_SPEED 10000 #define MIDI_CHANNEL 4 #define PINS 15 int pinArray[] = {13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 14, 15, 16}; int timer = 100; int currentSpeaker=0; boolean goingBack=false; Timer change; unsigned long currentTime; MIDI_CREATE_DEFAULT_INSTANCE(); void startTimer(Timer* timer,long interval,boolean repeat,void (*callbackFunction)()); void handleNoteOn(byte inChannel, byte inNote, byte inVelocity) { if(inNote0)stepDown(); else { goingBack=false; stepUp(); } } } void rnd() { int nextSpeaker=random(PINS); digitalWrite(pinArray[currentSpeaker], LOW); digitalWrite(pinArray[nextSpeaker], HIGH); currentSpeaker=nextSpeaker; } void startTimer(Timer* timer,long interval,boolean repeat,void (*callbackFunction)()) { // Serial.println("timer started"); timer->startTime=currentTime; timer->interval=interval; timer->repeat=repeat; timer->callbackFunction=*callbackFunction; timer->running=true; } void checkTimer(Timer* timer) { //Serial.println("timer check"); if(timer->running && (currentTime - timer->startTime > timer->interval)) { timer->callbackFunction(); //Serial.println("timer step"); if(timer->repeat) { //resetTimer timer->startTime=currentTime; // Serial.println("timer reset"); } else { //stopTimer timer->running=false; } } } void stopTimer(Timer* timer) { timer->running=false; }