Got encoders working, fixed clock calcs, added output for lanes 2 and 3.
This commit is contained in:
parent
ca1c968d84
commit
3287c86f4c
1 changed files with 49 additions and 5 deletions
54
Lanes.ino
54
Lanes.ino
|
@ -23,9 +23,10 @@ bool E2Btn = false;
|
|||
bool ClockState = false;
|
||||
int PpQN = 24;
|
||||
float Clock = 120;
|
||||
float ClockTick = 1/((Clock * PpQN)/60);
|
||||
float ClockTick = (1/((Clock * PpQN)/60)) * 1000;
|
||||
unsigned long ClockTime = 0;
|
||||
unsigned long LastStepTime = 0;
|
||||
long EncLeft, EncRight = 0;
|
||||
long Lane1Pos, Lane2Pos, Lane3Pos, Lane1Time, Lane2Time, Lane3Time = 0;
|
||||
|
||||
//Lanes are 4 dimensions 0 = Step Time, 1 = Step Voltage, 2 = Curve type (Linear, Expo, Log, Sine, etc) 3 = Curve Parameter.
|
||||
|
@ -37,7 +38,7 @@ void setup() {
|
|||
|
||||
//Open Serial for output prior to installing a screen
|
||||
Serial.begin( 115200 );
|
||||
|
||||
Serial.println("Env Gen");
|
||||
randomSeed(analogRead(A7));
|
||||
|
||||
//Clear the Lanes
|
||||
|
@ -46,9 +47,14 @@ void setup() {
|
|||
Lane1[1][i] = random(0, 255);
|
||||
Lane1[2][i] = random(0, 2);
|
||||
Lane1[3][i] = random(0,255);
|
||||
for(int j = 0; j < 4; j++){
|
||||
Lane2[j][i] = Lane3[i][j] = 0;
|
||||
}
|
||||
Lane2[0][i] = random(0, 96);
|
||||
Lane2[1][i] = random(0, 255);
|
||||
Lane2[2][i] = random(0, 2);
|
||||
Lane2[3][i] = random(0,255);
|
||||
Lane3[0][i] = random(0, 96);
|
||||
Lane3[1][i] = random(0, 255);
|
||||
Lane3[2][i] = random(0, 2);
|
||||
Lane3[3][i] = random(0,255);
|
||||
}
|
||||
|
||||
analogWrite( Lane1Pin, Lane1[1][0]);
|
||||
|
@ -59,6 +65,34 @@ void loop() {
|
|||
|
||||
delay(1);
|
||||
|
||||
long newLEnc = LeftEnc.read();
|
||||
long newREnc = RightEnc.read();
|
||||
|
||||
if (newLEnc != EncLeft || newREnc != EncRight){
|
||||
String output = "Left Enc Pos: ";
|
||||
output.concat(newLEnc);
|
||||
output.concat( ", Right Enc Pos: ");
|
||||
output.concat(newREnc);
|
||||
Serial.print(output);
|
||||
|
||||
if (newLEnc != EncLeft){
|
||||
Clock = Clock + (((float)EncLeft - (float)newLEnc)/40.0);
|
||||
} else{
|
||||
Clock = Clock + ((EncRight - newREnc) * 2.5);
|
||||
}
|
||||
|
||||
ClockTick = (1/((Clock * PpQN)/60)) * 1000;
|
||||
EncLeft = newLEnc;
|
||||
EncRight = newREnc;
|
||||
output = " Clock: ";
|
||||
output.concat(Clock);
|
||||
output.concat( " Clocktick: ");
|
||||
output.concat( ClockTick);
|
||||
|
||||
Serial.println(output);
|
||||
|
||||
}
|
||||
|
||||
unsigned long currentTime = millis();
|
||||
|
||||
if ((currentTime - LastStepTime) > ClockTick){
|
||||
|
@ -71,4 +105,14 @@ void loop() {
|
|||
Lane1Time = ClockTime;
|
||||
analogWrite(Lane1Pin, Lane1[1][Lane1Pos]);
|
||||
}
|
||||
if ((ClockTime - Lane2Time) > Lane2[0][Lane2Pos]){
|
||||
Lane2Pos = (Lane2Pos + 1) & B00001111;
|
||||
Lane2Time = ClockTime;
|
||||
analogWrite(Lane2Pin, Lane2[1][Lane2Pos]);
|
||||
}
|
||||
if ((ClockTime - Lane3Time) > Lane3[0][Lane3Pos]){
|
||||
Lane3Pos = (Lane3Pos + 1) & B00001111;
|
||||
Lane3Time = ClockTime;
|
||||
analogWrite(Lane3Pin, Lane3[1][Lane3Pos]);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue