531 lines
24 KiB
Plaintext
531 lines
24 KiB
Plaintext
import processing.serial.*;
|
|
|
|
int bpm = 110;
|
|
int minBpm = 40;
|
|
int maxBpm = 220;
|
|
|
|
boolean running = true;
|
|
|
|
int delayMs = (int)(60000/bpm)/4;
|
|
int beat = 1;
|
|
|
|
float controlX = map(bpm, minBpm, maxBpm, 0, 400);
|
|
boolean isChangingBpm = false;
|
|
|
|
|
|
int ledStartX = 40;
|
|
int ledStartY = 40;
|
|
int ledDiam = 70;
|
|
int ledInc = 75;
|
|
|
|
ArrayList<byte[]> byteCodes = new ArrayList<byte[]>();
|
|
ArrayList<Serial> playdates = new ArrayList<Serial>();
|
|
|
|
void setup(){
|
|
size(308, 420);
|
|
PFont font = createFont("font.ttf", 40);
|
|
textFont(font);
|
|
surface.setTitle("Playdate Clock");
|
|
byteCodes.add(loadBytes("clock1.luac"));
|
|
byteCodes.add(loadBytes("clock2.luac"));
|
|
byteCodes.add(loadBytes("clock3.luac"));
|
|
byteCodes.add(loadBytes("clock4.luac"));
|
|
byteCodes.add(loadBytes("clock5.luac"));
|
|
byteCodes.add(loadBytes("clock6.luac"));
|
|
byteCodes.add(loadBytes("clock7.luac"));
|
|
byteCodes.add(loadBytes("clock8.luac"));
|
|
byteCodes.add(loadBytes("clock9.luac"));
|
|
byteCodes.add(loadBytes("clock10.luac"));
|
|
byteCodes.add(loadBytes("clock11.luac"));
|
|
byteCodes.add(loadBytes("clock12.luac"));
|
|
byteCodes.add(loadBytes("clock13.luac"));
|
|
byteCodes.add(loadBytes("clock14.luac"));
|
|
byteCodes.add(loadBytes("clock15.luac"));
|
|
byteCodes.add(loadBytes("clock16.luac"));
|
|
|
|
String[] serialDevices = Serial.list();
|
|
int deviceCount = serialDevices.length;
|
|
for(int i = 0; i < deviceCount ; i++){
|
|
String device = serialDevices[i];
|
|
if(device.contains("cu.usbmodemPDU1")){
|
|
println("Found a Playdate at " + device);
|
|
playdates.add(new Serial(this, device, 115200));
|
|
}
|
|
}
|
|
|
|
strokeWeight(2);
|
|
|
|
thread("clockThread");
|
|
}
|
|
|
|
void draw() {
|
|
background(205);
|
|
|
|
fill(0);
|
|
if(running){
|
|
rect(250, 320, 40, 40);
|
|
}else{
|
|
triangle(250, 320, 290, 340, 250, 360);
|
|
}
|
|
|
|
stroke(255);
|
|
if(!running){
|
|
noFill();
|
|
ellipse(ledStartX, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
}else{
|
|
if(beat == 1){
|
|
fill(0);
|
|
ellipse(ledStartX, ledStartY, ledDiam, ledDiam);
|
|
|
|
noFill();
|
|
ellipse(ledStartX + ledInc, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
|
|
|
|
}else if(beat == 2){
|
|
fill(0);
|
|
ellipse(ledStartX, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY, ledDiam, ledDiam);
|
|
|
|
noFill();
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
}else if(beat == 3){
|
|
fill(0);
|
|
ellipse(ledStartX, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY, ledDiam, ledDiam);
|
|
|
|
noFill();
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
}else if(beat == 4){
|
|
fill(0);
|
|
ellipse(ledStartX, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY, ledDiam, ledDiam);
|
|
|
|
noFill();
|
|
ellipse(ledStartX, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
}else if(beat == 5){
|
|
fill(0);
|
|
ellipse(ledStartX, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
noFill();
|
|
ellipse(ledStartX + ledInc, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
}else if(beat == 6){
|
|
fill(0);
|
|
ellipse(ledStartX, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
noFill();
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
}else if(beat == 7){
|
|
fill(0);
|
|
ellipse(ledStartX, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
noFill();
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
}else if(beat == 8){
|
|
fill(0);
|
|
ellipse(ledStartX, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
noFill();
|
|
ellipse(ledStartX, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
}else if(beat == 9){
|
|
fill(0);
|
|
ellipse(ledStartX, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
noFill();
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
}else if(beat == 10){
|
|
fill(0);
|
|
ellipse(ledStartX, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
noFill();
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
}else if(beat == 11){
|
|
fill(0);
|
|
ellipse(ledStartX, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
noFill();
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
}else if(beat == 12){
|
|
fill(0);
|
|
ellipse(ledStartX, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
noFill();
|
|
ellipse(ledStartX, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
}else if(beat == 13){
|
|
fill(0);
|
|
ellipse(ledStartX, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
|
|
noFill();
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
}else if(beat == 14){
|
|
fill(0);
|
|
ellipse(ledStartX, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
|
|
noFill();
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
}else if(beat == 15){
|
|
fill(0);
|
|
ellipse(ledStartX, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
|
|
noFill();
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
}else if(beat == 16){
|
|
fill(0);
|
|
ellipse(ledStartX, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + ledInc, ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + ledInc, ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 2), ledDiam, ledDiam);
|
|
|
|
ellipse(ledStartX, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + ledInc, ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 2), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
ellipse(ledStartX + (ledInc * 3), ledStartY + (ledInc * 3), ledDiam, ledDiam);
|
|
}else{
|
|
//
|
|
}
|
|
}
|
|
|
|
noStroke();
|
|
|
|
//control:
|
|
fill(255);
|
|
noStroke();
|
|
rect(0, height - 50, width, height);
|
|
|
|
stroke(0);
|
|
line(15, height - 25, width - 15, height - 25);
|
|
|
|
fill(0);
|
|
noStroke();
|
|
rect(controlX, height - 40, 10, 30);
|
|
fill(255);
|
|
text(bpm + "BPM", 10, 360);
|
|
}
|
|
|
|
void mousePressed(){
|
|
if(mouseX > 250 && mouseY > 320 && mouseX < 280 && mouseY < 360){
|
|
running = !running;
|
|
|
|
//Just restarted after a pause - reset to beat 1
|
|
if(running){
|
|
beat = 1;
|
|
}
|
|
}else if(mouseX > controlX && mouseX < controlX + 10){
|
|
isChangingBpm = true;
|
|
}
|
|
}
|
|
|
|
void mouseReleased(){
|
|
isChangingBpm = false;
|
|
}
|
|
|
|
void mouseDragged(){
|
|
int change = pmouseX - mouseX;
|
|
if(change < 0 && bpm < maxBpm){
|
|
bpm += 2;
|
|
}else if (change > 0 && bpm > minBpm){
|
|
bpm -= 2;
|
|
}
|
|
|
|
delayMs = (int)(60000/bpm)/4;
|
|
controlX = map(bpm, minBpm, maxBpm, 20, width - 30);
|
|
}
|
|
|
|
void clockThread() {
|
|
for (;; delay(delayMs)){
|
|
|
|
byte[] byteCode = byteCodes.get(beat-1);
|
|
|
|
if(beat == 16){
|
|
beat = 0;
|
|
}
|
|
|
|
for(int i=0 ; i < playdates.size() ; i++){
|
|
if(running){
|
|
Serial playdate = playdates.get(i);
|
|
playdate.write("eval " + byteCode.length + "\n");
|
|
playdate.write(byteCode);
|
|
}
|
|
}
|
|
|
|
|
|
beat++;
|
|
}
|
|
}
|