I’m currently trying to add some characters to the rainbowduino( ie: ?, !, #, $, %, (, ) … ) so I’ve made this little tool to help make the codes. I figured other might find it useful as well if they want to add other characters. i’ll also be adding the updated rainbowduino code later on as well.
I’ve written it in processing. It’s pretty self explanatory. Just hit print to print out the hex string needed to display the object.
//GLOBAL VARIABLES
int[][] LEDGrid = new int[8][8]; //used to remember which led's have been selected
void setup() {
size(450, 250, P3D); //x, y
background(0);
//set up the grid
for ( int x = 0; x < 8; x++ ) {
for ( int y = 0; y < 8; y++ ) {
int xCoord = 20 + 30 * x;
int yCoord = 20 + 30 * y;
stroke( 255 );
fill( 155 );
ellipse( xCoord, yCoord, 25, 25 );
}
}
//Reset and Print buttons
fill( 255, 0, 0 );
quad ( 300, 90, 400, 90, 400, 110, 300, 110 );
fill( 0, 0, 255 );
quad ( 300, 150, 400, 150, 400, 170, 300, 170 );
fill( 255 );
text( "RESET", 330, 98, 80, 15 );
text( "PRINT", 330, 158, 80, 15 );
}
void draw() {
int pcOffset = 300;
}
void mouseClicked() {
/*
#### STUFF FOR SELECTING LEDS ####
*/
int xEllipse = 0;
int yEllipse = 0;
int xCenter = 0;
int yCenter = 0;
boolean xSet = false;
boolean ySet = false;
int buffer = 12;
for ( int x=0; x<8; x++) {
if ( mouseX > ( 20 + 30 * x -12 ) && mouseX < (20 + 30 * ( x + 1 ) - 12 ) ) {
xEllipse = x;
xCenter = 20 + 30 * x;
xSet = true;
}
}
for ( int y=0; y<8; y++) {
if ( mouseY > ( 20 + 30 * y - 12 ) && mouseY < (20 + 30 * ( y + 1 ) - 12 ) ) {
yEllipse = y;
yCenter = 20 + 30 * y;
ySet = true;
}
}
//check if they've clicked in a box, if they have, mark that LED
if ( xSet && ySet ) {
LEDGrid[ xEllipse ][ yEllipse ] = 1;
fill( 0, 255, 0 );
ellipse( xCenter, yCenter, 25, 25 );
}
/*
#### STUFF TO RESET AND PRINT CODES ####
*/
if ( mouseX > 300 && mouseX < 400 && mouseY >90 && mouseY<110 ) {
setup(); //reset the display
LEDGrid = new int[8][8];
}
if ( mouseX > 300 && mouseX < 400 && mouseY >150 && mouseY<170 ) {
makeInstruction(); //make the code
}
}
void makeInstruction() {
int rowTotal = 0;
String row;
print( "{" );
for ( int y = 7; y >= 0; y-- ) {
print( "0x" );
for ( int x = 7; x >= 0; x-- ) {
if ( LEDGrid[ x ][ y ] == 1 ) {
rowTotal += pow ( 2, x ); //convert LED values to binary
}
}
row = convertToHex( rowTotal );
if ( y != 0 ) {
print( row + "," );
}
else {
print( row );
}
rowTotal = 0;
}
print( "} \n");
}
String convertToHex( int x ) {
//has to be the mirror opposite!
//more information about this process available at:
// http://sites.google.com/site/joetcochran/thejoyliteproject
int firstHex = 0;
int secondHex = 0;
String firstHexChar;
String secondHexChar;
//get the first and second hex values in binary form
firstHex = x / 16;
secondHex = x - firstHex * 16;
firstHexChar = hex( firstHex, 1 ); //convert values to hex
secondHexChar = hex( secondHex, 1 );
//concatenate the strings
String result = firstHexChar + secondHexChar;
return result;
}