Created
May 16, 2013 21:57
-
-
Save boxysean/5595440 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Tlc5940.h" | |
int delayTime = 1; | |
int analogPin[8] = { | |
A0, A1, A2, A3, A4, A5, 2, 1}; | |
char cmd; | |
int edgeLength = 2; | |
int layMin = 3; | |
int layMax = 4; | |
int colMin = 27; | |
int colMax = 36; | |
boolean hitBack = false; | |
boolean hitRight = false; | |
boolean hitLeft = false; | |
boolean hitFront = false; | |
boolean hitTop = false; | |
boolean hitBottom = false; | |
void setup() { | |
Tlc.init(); | |
Serial.begin(9600); | |
for(int pin = 0; pin < 8; pin++){ | |
pinMode(analogPin[pin], OUTPUT); | |
digitalWrite(analogPin[pin], HIGH); // TURN OFF LEDs | |
} | |
} | |
void loop() { | |
Tlc.clear(); | |
if (edgeLength == 2) { | |
// Bounds Checking (Layers) | |
if (layMin < 0) { | |
layMin = 0; | |
layMax = 1; | |
} | |
if (layMax > 7) { | |
layMin = 6; | |
layMax = 7; | |
} | |
// Bounds Checking (Columns) | |
// Corners | |
if (colMin == 0) { | |
hitBack = true; | |
hitRight = true; | |
} | |
else if (colMin == 6) { | |
hitBack = true; | |
hitLeft = true; | |
} | |
else if (colMax == 63) { | |
hitFront = true; | |
hitLeft = true; | |
} | |
else if (colMax == 57) { | |
hitFront = true; | |
hitRight = true; | |
} | |
// Back Wall | |
else if (colMin == 1 || colMin == 2 || colMin == 3 || colMin == 4 || colMin == 5 | |
|| colMin == 6) { | |
hitBack = true; | |
hitRight = false; | |
hitLeft = false; | |
hitFront = false; | |
} | |
// Right Wall | |
else if (colMin == 8 || colMin == 16 || colMin == 24 || colMin == 32 || colMin == 40 | |
|| colMin == 48 || colMin == 56) { | |
hitBack = false; | |
hitRight = true; | |
hitLeft = false; | |
hitFront = false; | |
} | |
// Left Wall | |
else if (colMax == 15 || colMax == 23 || colMax == 31 || colMax == 39 | |
|| colMax == 47 || colMax == 55) { | |
hitBack = false; | |
hitRight = false; | |
hitLeft = true; | |
hitFront = false; | |
} | |
// Front Wall | |
else if (colMax == 57 || colMax == 58 || colMax == 59 || colMax == 60 | |
|| colMax == 61 || colMax == 62 || colMax == 63) { | |
hitBack = false; | |
hitRight = false; | |
hitLeft = false; | |
hitFront = true; | |
} | |
else { | |
hitBack = false; | |
hitRight = false; | |
hitLeft = false; | |
hitFront = false; | |
hitTop = false; | |
hitBottom = false; | |
} | |
for (int layer = layMin; layer <= layMax; layer++) { | |
digitalWrite(analogPin[layer], LOW); | |
for (int column = colMin; column <= (colMax - 8); column++) { | |
Tlc.set(column, 4095); | |
} | |
for (int column = (colMin + 8); column <= colMax; column++) { | |
Tlc.set(column, 4095); | |
} | |
delay(delayTime); | |
digitalWrite(analogPin[layer], HIGH); | |
Tlc.update(); | |
} | |
} | |
else if (edgeLength == 4) { | |
// Bounds Checking (Layers) | |
if (layMin < 1) { | |
layMin = 1; | |
layMax = 2; | |
} | |
if (layMax > 6) { | |
layMin = 5; | |
layMax = 6; | |
} | |
// Bounds Checking (Columns) | |
// Corners | |
if (colMin == 9) { | |
hitBack = true; | |
hitRight = true; | |
} | |
else if (colMin == 13) { | |
hitBack = true; | |
hitLeft = true; | |
} | |
else if (colMax == 54) { | |
hitFront = true; | |
hitLeft = true; | |
} | |
else if (colMax == 50) { | |
hitFront = true; | |
hitRight = true; | |
} | |
// Back Wall | |
else if (colMin == 9 || colMin == 10 || colMin == 11 || colMin == 12 || colMin == 13 | |
|| colMin == 14) { | |
hitBack = true; | |
hitRight = false; | |
hitLeft = false; | |
hitFront = false; | |
} | |
// Right Wall | |
else if (colMin == 9 || colMin == 17 || colMin == 25 || colMin == 33 || colMin == 41 | |
|| colMin == 49 || colMin == 57) { | |
hitBack = false; | |
hitRight = true; | |
hitLeft = false; | |
hitFront = false; | |
} | |
// Left Wall | |
else if (colMax == 14 || colMax == 22 || colMax == 30 || colMax == 38 | |
|| colMax == 46 || colMax == 54) { | |
hitBack = false; | |
hitRight = false; | |
hitLeft = true; | |
hitFront = false; | |
} | |
// Front Wall | |
else if (colMax == 54 || colMax == 53 || colMax == 52 || colMax == 51 | |
|| colMax == 50 || colMax == 49) { | |
hitBack = false; | |
hitRight = false; | |
hitLeft = false; | |
hitFront = true; | |
} | |
else { | |
hitBack = false; | |
hitRight = false; | |
hitLeft = false; | |
hitFront = false; | |
hitTop = false; | |
hitBottom = false; | |
} | |
for (int layer = (layMin - 1); layer <= (layMax + 1) ; layer++) { | |
digitalWrite(analogPin[layer], LOW); | |
for (int column = (colMin - 9); column <= (colMax - 15); column++) { | |
Tlc.set(column, 4095); | |
} | |
for (int column = (colMin - 1); column <= (colMax - 7); column++) { | |
Tlc.set(column, 4095); | |
} | |
for (int column = (colMin + 7); column <= (colMax + 1); column++) { | |
Tlc.set(column, 4095); | |
} | |
for (int column = (colMin + 15); column <= (colMax + 9); column++) { | |
Tlc.set(column, 4095); | |
} | |
delay(delayTime); | |
digitalWrite(analogPin[layer], HIGH); | |
Tlc.update(); | |
} | |
} | |
else if (edgeLength == 6) { | |
// Bounds Checking (Layers) | |
if (layMin < 2) { | |
layMin = 2; | |
layMax = 3; | |
} | |
if (layMax > 5) { | |
layMin = 4; | |
layMax = 5; | |
} | |
// Bounds Checking (Columns) | |
// Corners | |
if (colMin == 18) { | |
hitBack = true; | |
hitRight = true; | |
} | |
else if (colMin == 20) { | |
hitBack = true; | |
hitLeft = true; | |
} | |
else if (colMax == 45) { | |
hitFront = true; | |
hitLeft = true; | |
} | |
else if (colMax == 43) { | |
hitFront = true; | |
hitRight = true; | |
} | |
// Back Wall | |
else if (colMin == 19) { | |
hitBack = true; | |
hitRight = false; | |
hitLeft = false; | |
hitFront = false; | |
} | |
// Right Wall | |
else if (colMin == 26){ | |
hitBack = false; | |
hitRight = true; | |
hitLeft = false; | |
hitFront = false; | |
} | |
// Left Wall | |
else if (colMax == 37) { | |
hitBack = false; | |
hitRight = false; | |
hitLeft = true; | |
hitFront = false; | |
} | |
// Front Wall | |
else if (colMax == 44) { | |
hitBack = false; | |
hitRight = false; | |
hitLeft = false; | |
hitFront = true; | |
} | |
else { | |
hitBack = false; | |
hitRight = false; | |
hitLeft = false; | |
hitFront = false; | |
hitTop = false; | |
hitBottom = false; | |
} | |
for (int layer = (layMin - 2); layer <= (layMax + 2); layer++) { | |
digitalWrite(analogPin[layer], LOW); | |
for (int column = (colMin - 18); column <= (colMax - 22); column++) { | |
Tlc.set(column, 4095); | |
} | |
for (int column = (colMin - 10); column <= (colMax - 14); column++) { | |
Tlc.set(column, 4095); | |
} | |
for (int column = (colMin - 2); column <= (colMax - 6); column++) { | |
Tlc.set(column, 4095); | |
} | |
for (int column = (colMin + 6); column <= (colMax + 2); column++) { | |
Tlc.set(column, 4095); | |
} | |
for (int column = (colMin + 14); column <= (colMax + 10); column++) { | |
Tlc.set(column, 4095); | |
} | |
for (int column = (colMin + 22); column <= (colMax + 18); column++) { | |
Tlc.set(column, 4095); | |
} | |
delay(delayTime); | |
digitalWrite(analogPin[layer], HIGH); | |
Tlc.update(); | |
} | |
} | |
else if (edgeLength == 8) { | |
// Bounds Checking (Layers) | |
if (layMin < 0) { | |
layMin = 0; | |
layMax = 7; | |
} | |
if (layMax > 7) { | |
layMin = 0; | |
layMax = 7; | |
} | |
// Bounds Check (Columns) | |
hitBack = true; | |
hitRight = true; | |
hitLeft = true; | |
hitFront = true; | |
hitTop = true; | |
hitBottom = true; | |
for (int layer = (layMin - 3); layer <= (layMax + 3); layer++){ | |
digitalWrite(analogPin[layer], LOW); | |
for (int column = 0; column < 64; column++) { | |
Tlc.set(column, 4095); | |
} | |
delay(delayTime); | |
digitalWrite(analogPin[layer], HIGH); | |
Tlc.update(); | |
} | |
} | |
} | |
void serialEvent() { | |
if (Serial.available()) { | |
cmd = Serial.read(); | |
if (cmd == 'U') { | |
if (hitBack == false) { | |
colMin-=8; | |
colMax-=8; | |
} | |
} | |
if (cmd == 'D') { | |
if (hitFront == false) { | |
colMin+=8; | |
colMax+=8; | |
} | |
} | |
if (cmd == 'L') { | |
if (hitLeft == false) { | |
colMin++; | |
colMax++; | |
} | |
} | |
if (cmd == 'R') { | |
if (hitRight == false) { | |
colMin--; | |
colMax--; | |
} | |
} | |
if (cmd == 'W') { | |
layMin--; | |
layMax--; | |
} | |
if (cmd == 'S') { | |
layMin++; | |
layMax++; | |
} | |
if (cmd == 'Z') { | |
// Bounds Checking (Size) | |
if (edgeLength > 8) { | |
edgeLength = 2; | |
// Reset all Variables | |
layMin = 3; | |
layMax = 4; | |
colMin = 27; | |
colMax = 36; | |
} | |
else { | |
edgeLength+=2; | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.serial.*; | |
Serial myPort; | |
void setup() | |
{ | |
String portName = Serial.list()[0]; | |
myPort = new Serial(this, portName, 9600); | |
} | |
void draw() { | |
// NUTIN' | |
} | |
void keyPressed() { | |
if (key == CODED) { | |
if (keyCode == UP) { | |
println("UP"); | |
myPort.write('U'); | |
} | |
else if (keyCode == DOWN) { | |
println("DOWN"); | |
myPort.write('D'); | |
} | |
else if (keyCode == LEFT) { | |
println("LEFT"); | |
myPort.write('L'); | |
} | |
else if (keyCode == RIGHT) { | |
println("RIGHT"); | |
myPort.write('R'); | |
} | |
} | |
else if (key == 'w' || key == 'W') { | |
println("UP"); | |
myPort.write('W'); | |
} | |
else if (key == 's' || key == 'S') { | |
println("DOWN"); | |
myPort.write('S'); | |
} | |
else if (key == ENTER) { | |
println("KABOOM"); | |
myPort.write('K'); | |
} | |
else if (key == ' ') { | |
println("SPACE"); | |
myPort.write('Z'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Tlc5940.h" | |
int delayTime = 1; | |
//int analogPin[8] = { A0, A1, A2, A3, A4, A5, 2, 1}; | |
int analogPin[8] = { | |
A0, A1, A2, A3, A4, A5, 2, 2}; | |
char buffer[64]; | |
void setup() { | |
Tlc.init(); | |
Serial.begin(9600); | |
for(int pin = 0; pin < 8; pin++){ | |
pinMode(analogPin[pin], OUTPUT); | |
digitalWrite(analogPin[pin], HIGH); // TURN OFF LEDs | |
} | |
for (int i = 0; i < 64; i++) { | |
buffer[i] = 0; | |
} | |
} | |
void loop() { | |
Tlc.clear(); | |
for (int layer = 0; layer < 8; layer++) { | |
digitalWrite(analogPin[layer], LOW); | |
for (int row = 0; row < 8; row++) { | |
for (int mask = 1, column = 0; column < 8; mask <<= 1, column++) { | |
if ((mask & buffer[layer * 8 + row]) != 0) { | |
Tlc.set(row * 8 + column, 4095); | |
} | |
} | |
} | |
delay(delayTime); | |
digitalWrite(analogPin[layer], HIGH); | |
Tlc.update(); | |
} | |
} | |
void serialEvent() { | |
if (Serial.available() >= 63) { | |
Serial.readBytes(buffer, 63); | |
Serial.println("recvd "); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.serial.*; | |
Serial myPort; | |
int cube[][][] = new int[8][8][8]; | |
byte buffer[] = new byte[8*8]; | |
int brightnessThreshold = 64; | |
int ON = 127; | |
int OFF = 0; | |
void setup() | |
{ | |
String portName = Serial.list()[0]; | |
myPort = new Serial(this, portName, 9600); | |
} | |
void draw() { | |
for (int layer = 0; layer < 8; layer++) { | |
for (int row = 0; row < 8; row++) { | |
for (int column = 0; column < 8; column++) { | |
cube[layer][row][column] = ON; | |
cubeSerialWrite(); | |
System.out.printf("l %d r %d c %d\n", layer, row, column); | |
delay(100); | |
cube[layer][row][column] = OFF; | |
} | |
} | |
} | |
} | |
byte[] smallBuffer = new byte[1]; | |
void cubeSerialWrite() { | |
for (int l = 0; l < 8; l++) { | |
for (int r = 0; r < 8; r++) { | |
int idx = l * 8 + r; | |
buffer[idx] = 0; | |
for (int c = 0, m = 1; c < 8; c++, m <<= 1) { | |
if (cube[l][r][c] >= brightnessThreshold) { | |
buffer[idx] |= m; | |
} | |
} | |
} | |
} | |
myPort.write(buffer); | |
} | |
void serialEvent(Serial p) { | |
String s = p.readString(); | |
print(s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment