Skip to content

Instantly share code, notes, and snippets.

@frogwoo
Created August 30, 2016 21:22
Show Gist options
  • Save frogwoo/60c453b92b0fa21fec37286974dbd864 to your computer and use it in GitHub Desktop.
Save frogwoo/60c453b92b0fa21fec37286974dbd864 to your computer and use it in GitHub Desktop.
An example for controlling the Pi-Lite with Processing
import processing.serial.*;
Serial port;
String portID = "/dev/ttyAMA0";
int squareSize = 80;
int[] colColours = {#061A07,#072409,#0F4812,#136A18,#198B20,#1DA724,#20C629,#36FF41};
int[] colLengths = {9,8,7,6,5,4,3,2};
int selectedCol = 3;
void setup() {
size(540,270);
background(255);
port = new Serial(this,portID,9600);
port.write("$$$ALL,OFF");
}
boolean changed = true;
void draw() {
background(255);
if (changed) {
port.write("$$$ALL,OFF\r");
}
for (int i = 0; i < width; i+= squareSize) {
if (i / squareSize == selectedCol) {
strokeWeight(4);
} else {
strokeWeight(1);
}
fill(colColours[i/squareSize]);
rect(i,0,squareSize, (colLengths[i / squareSize]) * 30);
if (changed) {
int h = int(map(colLengths[i / squareSize],0,9,0,100));
String on1 = "$$$B" + (13-i / 40) + "," + h + ",ON\r";
String on2 = "$$$B" + (13-i / 40+1) + "," + h + ",ON\r";
port.write(on1);
port.write(on2);
}
}
changed = false;
}
void keyPressed() {
if (keyCode == LEFT) {
if (selectedCol != 0) {
selectedCol -= 1;
}
}
if (keyCode == RIGHT) {
if (selectedCol != 7) {
selectedCol += 1;
}
}
if (keyCode == DOWN) {
if (colLengths[selectedCol] != 9) {
colLengths[selectedCol] += 1;
changed = true;
}
}
if (keyCode == UP) {
if (colLengths[selectedCol] != 0) {
colLengths[selectedCol] -= 1;
changed = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment