Need to create a pixel array in processing and stream it to my arduino
in
Integration and Hardware
•
1 years ago
Hi, I am buiding an led sphere in arduino. I have made a spining wheel of leds. The arduino checks a 40 step encoder wheel via inputs from a photo interrupter then on every step of the encoder wheel, it reads 16 values from an array to light up 16 vertically placed RGB leds on the wspinning wheel. It works fine but now I want to take it to the next level and use processing to streat the data to the arduino. I want to do this so that I am not limited to the internal memory on the arduino. I am hoping to switch from an arduino mega to an arduino mini board. The format I am using is this {1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0},{1,2,3....etc (40 times)},
The 16 digits within brackets represent the 16 leds and the 0-3 values represent: 0=off, 1 = green, 2= blue, 3=red.
What I would love to do in processing is to build a grid 40horizontal x 16 vertical and use the ouse to fill in the squares with any of the 3 colors. once the grid is drawn, I would like to send it to arduino serially but still have it only process 16 pieces of data every time the encoder wheel moves to the next step.....40 steps is a full revolution.
I know this is a lot of help to ask for but I am new to processing and could use any help I can....even if it is just a rough idea of how to approach the writting of this code....
Hope one of you can help...
I did find the following code which creates the grid and allows me to draw in one color...just need to turn it into 3 colos and then have processing generate the array and feed it to my arduino board.
[code]
int pSize = 20;
int w = 800;
int h = 600;
int cols = w/pSize;
int rows = h/pSize;
int num = rows*cols;
Pixel[] pixel = new Pixel[num];
void setup() {
size(w,h);
smooth();
background(0);
rectMode(CENTER);
int c = 0;
for (int x=0; x<cols; x++){
for (int y=0; y<rows; y++){
pixel[c] = new Pixel((pSize/2)+x*pSize,(pSize/2)+y*pSize);
c++ ;
}
}
}
void draw() {
background(0);
for (int i=0; i<pixel.length; i++){
pixel[i].show();
}
}
class Pixel{
float x ;
float y ;
boolean on = false;
boolean turned = false;
Pixel(int _x, int _y){
x = _x;
y = _y;
}
void setOn(boolean t){
}
void show() {
float r = pSize/2.0;
fill(255);
if(mouseX >=x-r && mouseX<=x+r && mouseY >=y-r && mouseY<=y+r ){
if(mousePressed && turned == false) { on = !on; turned = true;}
} else {
turned = false;
}
if(on)fill(255,0,0);
rect(x,y,pSize,pSize);
}
}
1