hi im jonny. i have problem about interfacing arduino. im new in arduino. and try about interfacing turn on/off led matrix
this my sketch in processing
import processing.serial.*;
Serial myserial;
Lingkaran[][] link;
int baris=8;
int kolom=8;
int wid = 300;
int heig = 300;
void setup(){
int w = width/kolom;
int h = width/baris;
String portName = Serial.list()[0];
myserial = new Serial(this,portName, 9600);
size(wid,heig);
link = new Lingkaran[baris][kolom];
smooth();
for(int a=0;a<baris;a++){
for(int b=0;b<kolom;b++){
fill(255);
link[a][b] = new Lingkaran(a*25,b*25,w+9,h+9);
}
}
}
void draw(){
background(255);
// code for arduino
for(int a=0;a<baris;a++){
for(int b=0;b<kolom;b++){
link[a][b].display();
}
}
}
void mousePressed() {
for (int i = 0; i < baris; i++) {
for (int j = 0; j < kolom; j++) {
link[i][j].klik(mouseX,mouseY);
}
}
}
class Lingkaran {
private int x,y,w,h;
private int state;
public Lingkaran(int tempX, int tempY,int tempW, int tempH){
x = tempX;
y = tempY;
w = tempW;
h = tempH;
state = 0;
}
void display(){
noStroke();
if(state == 0){
fill(0,0,0);
}
else if(state == 1){
fill(255,0,0);
}
ellipse(x+w/2,y+h/2,w,h);
}
void klik(int mx,int my){
if (mx > x && mx < x + w && my > y && my < y + h) {
state = (state +1 ) % 2;
}
}
}
and sketch for arduino , communication with serial
int row[] = {10,11,12,13,14,15,16,17};
int col[] = {2,3,4,5,6,7,8,9};
int pixels[8][8];
int val;
void setup() {
Serial.begin(9600);
for (int thisPin = 0; thisPin < 8; thisPin++) {
pinMode(col[thisPin], OUTPUT);
pinMode(row[thisPin], OUTPUT);
digitalWrite(col[thisPin], HIGH);
}
// initialize the pixel matrix:
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
pixels[x][y] = HIGH;
}
}
}
void loop() {
readSensors();
refreshScreen();
}
void readSensors() {
if(Serial.available()){
val = Serial.read();
pixels[val][val] = LOW;
}
}
void refreshScreen() {
for (int thisRow = 0; thisRow < 8; thisRow++) {
digitalWrite(row[thisRow], HIGH);
for (int thisCol = 0; thisCol < 8; thisCol++) {
int thisPixel = pixels[thisRow][thisCol];
digitalWrite(col[thisCol], thisPixel);
if (thisPixel == LOW) {
digitalWrite(col[thisCol], HIGH);
}
}
digitalWrite(row[thisRow], LOW);
}
}
and for code for processing i have done. if u running code the processing . if u click one led in processing direct in arduino led on.
see the picture. if condition same in below even in arduino too.