Rebuilding for teensy - unfinished

This commit is contained in:
Lukas Bachschwell 2016-07-15 13:37:39 +02:00
parent f95db9c535
commit 8307efce95

View File

@ -1,8 +1,24 @@
#include <Adafruit_NeoPixel.h>
#include <MIDI.h> // Currently always asume with 2 pedals
//8 LEDs and Pin is 11
Adafruit_NeoPixel leds = Adafruit_NeoPixel(8, 11, NEO_GRB + NEO_KHZ800);
bool oldValues[9] = {
1, 1, 1, 1, 1, 1, 1, 1, 1}; bool oldValues[8] = {
1, 1, 1, 1, 1, 1, 1, 1
};
//byte counter;
byte CLOCK = 248;
byte START = 250;
byte CONTINUE = 251;
byte STOP = 252;
uint8_t pins[8] = {
17, 16, 15, 14, 2, 4, 3, 5
};
int tempState = 1; int tempState = 1;
int time = 0; int time = 0;
int bar = 1; int bar = 1;
@ -14,25 +30,25 @@ void tick()
if (time == 24) if (time == 24)
time = 0; time = 0;
if (bar == 4) if (bar == 4)
bar = 0; bar = 0;
if((time == 0)&&(bar == 0)) if ((time == 0) && (bar == 0))
digitalWrite(13,HIGH); digitalWrite(13, HIGH);
if(time == 3) if (time == 3)
digitalWrite(13,LOW); digitalWrite(13, LOW);
if(time == 0) if (time == 0)
bar++; bar++;
if((time == 0)&&(bar != 0)) if ((time == 0) && (bar != 0))
digitalWrite(12,HIGH); digitalWrite(12, HIGH);
if(time == 3) if (time == 3)
digitalWrite(12,LOW); digitalWrite(12, LOW);
time++; time++;
@ -47,89 +63,105 @@ void goClock()
void stopClock() void stopClock()
{ {
digitalWrite(13,LOW); digitalWrite(13, LOW);
digitalWrite(12,LOW); digitalWrite(12, LOW);
} }
void setup() {
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
MIDI.begin(MIDI_CHANNEL_OMNI);
MIDI.setHandleClock(tick);
MIDI.setHandleStart(goClock);
// MIDI.setHandleContinue(goClock);
MIDI.setHandleStop(stopClock);
//Modeled
digitalWrite(11,HIGH);
}
void loop() {
MIDI.read();
for(int i = 2; i <= 10; i++) {
tempState = digitalRead(i);
if(tempState != oldValues[i-2])
{
// debouncetime
delay(1);
tempState = digitalRead(i);
if(tempState != oldValues[i-2]){
/* if(i == 10)
{
if(tempState == 0)
MIDI.sendNoteOn(pedalNote, 127, 1);
else
MIDI.sendNoteOff(pedalNote, 0, 1);
}
else if(i == 7)
{
if(tempState == 0){
if(pedalNote == 10)
{
pedalNote = 11;
clearNote = 13;
digitalWrite(11,LOW);
}
else{
pedalNote = 10;
clearNote = 9;
digitalWrite(11,HIGH);
}
}
}
else if(i == 9)
{
if(tempState == 0)
MIDI.sendNoteOn(clearNote, 127, 1);
else
MIDI.sendNoteOff(clearNote, 0, 1);
}
else
{*/
if(tempState == 0)
MIDI.sendNoteOn(i, 127, 1);
else
MIDI.sendNoteOff(i, 0, 1);
// }
}
void RealTimeSystem(byte realtimebyte) {
if (realtimebyte == 248) {
tick();
} }
oldValues[i-2] = tempState;
if (realtimebyte == START || realtimebyte == CONTINUE) {
goClock();
}
if (realtimebyte == STOP) {
stopClock();
}
}
void setup() {
for (int i = 0; i < 8; i++) {
pinMode(pins[i], INPUT_PULLUP);
}
pinMode(13, OUTPUT); //LED
//MIDI.begin(MIDI_CHANNEL_OMNI);
// MIDI.setHandleClock(tick);
//MIDI.setHandleStart(goClock);
// // MIDI.setHandleContinue(goClock);
//MIDI.setHandleStop(stopClock);
//Modeled
// digitalWrite(11,HIGH);
usbMIDI.setHandleRealTimeSystem(RealTimeSystem);
leds.begin();
leds.show();
}
void loop() {
usbMIDI.read();
for (int i = 0; i < 8; i++) {
//Ned ganz
tempState = digitalRead(pins[i]);
if (tempState != oldValues[i - 2])
{
// debouncetime
delay(1);
tempState = digitalRead(pins[i]);
if (tempState != oldValues[i - 2]) {
/* if(i == 10)
{
if(tempState == 0)
MIDI.sendNoteOn(pedalNote, 127, 1);
else
MIDI.sendNoteOff(pedalNote, 0, 1);
}
else if(i == 7)
{
if(tempState == 0){
if(pedalNote == 10)
{
pedalNote = 11;
clearNote = 13;
digitalWrite(11,LOW);
}
else{
pedalNote = 10;
clearNote = 9;
digitalWrite(11,HIGH);
}
}
}
else if(i == 9)
{
if(tempState == 0)
MIDI.sendNoteOn(clearNote, 127, 1);
else
MIDI.sendNoteOff(clearNote, 0, 1);
}
else
{*/
if (tempState == 0) {
usbMIDI.sendNoteOn(i, 127, 1);
} else {
usbMIDI.sendNoteOff(i, 0, 1);
}
// }
}
}
oldValues[i - 2] = tempState;
} }
} }