Initial clock in, input pin changes. initial input stuff.

This commit is contained in:
Kara 2022-12-21 17:35:18 -05:00
parent 3287c86f4c
commit 33d39f2ce2

View file

@ -10,8 +10,8 @@ const int Enc1P2 = 14; //Encoder 1 Pin 2 to non-Interrupting pin because we onl
const int Enc2P2 = 15; //Encoder 2 Pin 2 to non-Interrupting pin because we only have 2 const int Enc2P2 = 15; //Encoder 2 Pin 2 to non-Interrupting pin because we only have 2
const int Enc1Btn = 16; //Encoder 1 Button const int Enc1Btn = 16; //Encoder 1 Button
const int Enc2Btn = 17; //Encoder 2 Button const int Enc2Btn = 17; //Encoder 2 Button
const int ClockIn = 20; //Clock In const int ClockIn = 4; //Clock In
const int ClockDetect = 21; //Detect clock jack const int ClockDetect = 7; //Detect clock jack
Encoder LeftEnc( Enc1P1, Enc1P2); Encoder LeftEnc( Enc1P1, Enc1P2);
Encoder RightEnc( Enc2P1, Enc2P2); Encoder RightEnc( Enc2P1, Enc2P2);
@ -21,6 +21,9 @@ int E2 = 0;
bool E1Btn = false; bool E1Btn = false;
bool E2Btn = false; bool E2Btn = false;
bool ClockState = false; bool ClockState = false;
bool E1Prev, E2Prev, CDPrev = false;
unsigned long ClockPrev = 0;
byte Input = 0;
int PpQN = 24; int PpQN = 24;
float Clock = 120; float Clock = 120;
float ClockTick = (1/((Clock * PpQN)/60)) * 1000; float ClockTick = (1/((Clock * PpQN)/60)) * 1000;
@ -41,6 +44,18 @@ void setup() {
Serial.println("Env Gen"); Serial.println("Env Gen");
randomSeed(analogRead(A7)); randomSeed(analogRead(A7));
pinMode(Enc1Btn, INPUT_PULLUP);
pinMode(Enc2Btn, INPUT_PULLUP);
pinMode(ClockIn, INPUT);
pinMode(ClockDetect, INPUT_PULLUP);
E1Btn = digitalRead(Enc1Btn);
E1Prev = E1Btn;
E2Btn = digitalRead(Enc2Btn);
E2Prev = E2Btn;
ClockState = digitalRead(ClockIn);
CDPrev = digitalRead(ClockDetect);
//Clear the Lanes //Clear the Lanes
for(int i = 0; i < 16; i++){ for(int i = 0; i < 16; i++){
Lane1[0][i] = random(0, 96); Lane1[0][i] = random(0, 96);
@ -58,16 +73,53 @@ void setup() {
} }
analogWrite( Lane1Pin, Lane1[1][0]); analogWrite( Lane1Pin, Lane1[1][0]);
analogWrite( Lane2Pin, Lane2[1][0]);
analogWrite( Lane3Pin, Lane3[1][0]);
} }
void loop() { void loop() {
delay(1); //delay(1);
long newLEnc = LeftEnc.read(); long newLEnc = LeftEnc.read();
long newREnc = RightEnc.read(); long newREnc = RightEnc.read();
if (digitalRead(Enc1Btn) != E1Btn){
Serial.println("E1Btn State Change");
E1Btn = !E1Btn;
}
if (digitalRead(Enc2Btn) != E2Btn){
Serial.println("E2Btn State Change");
E2Btn = !E2Btn;
}
if (digitalRead(ClockDetect) != CDPrev){
Serial.println("Clock Detect Change");
CDPrev = !CDPrev;
}
if ( digitalRead(ClockIn) != ClockState){
ClockState = !ClockState;
if (ClockState){
unsigned long tmpClock = micros();
float clkInTick = tmpClock - ClockPrev;
float newBPM = ((1.0/(clkInTick/1000000.0)) * 60.0)/(float)PpQN;
ClockPrev = tmpClock;
if (abs(Clock - newBPM) > 0.5){
Clock = newBPM;
String outputBPM = "New BPM: ";
outputBPM.concat(newBPM);
Serial.println(outputBPM);
outputBPM = "Clock Tick: ";
outputBPM.concat(clkInTick);
Serial.println(outputBPM);
ClockTick = (1/((Clock * PpQN)/60)) * 1000;
}
}
}
if (newLEnc != EncLeft || newREnc != EncRight){ if (newLEnc != EncLeft || newREnc != EncRight){
String output = "Left Enc Pos: "; String output = "Left Enc Pos: ";
output.concat(newLEnc); output.concat(newLEnc);