import processing.serial.*; Serial port; int baudrate = 9600; int[][] tempBitmap; int painter=1; //if we should paint on mouse down or not void setup() { size((64*2)*3, 64*4); smooth(); fill(126); tempBitmap = new int[8][8]; for (int i=0;i<8;i++) for (int ii=0;ii<8;ii++) tempBitmap[i][ii]=0; // List all the available serial ports: println(Serial.list()); try { port = new Serial(this, Serial.list()[0], baudrate); } catch(Exception e) { print(port); } if(port !=null) println(port); } void serialEvent(int serial) { println("HALP!!!"); } byte populateByteOn(byte x, byte value) { return x |= (1 << (7-value)); } byte populateByteOff(byte x, byte value) { return x &= (1 << (7-value)); } void keyPressed() { if (key == '1') { println(""); for (byte ii=0;ii<8;ii++) { byte myByte=0; for (byte i=0;i<8;i++) { if( tempBitmap[i][ii]==1) myByte= populateByteOn(myByte,i); } println("tempBitmap[i]["+ii+"] = (byte)unbinary(\""+ binary(myByte)+"\");"); } println("i++;"); } if (key == '2') { painter=1; } if (key == '3') { painter=0; } } void tjatjing() { if (mousePressed == true ) { byte myByte=0; /* if(tempBitmap[mouseX/(width/8)][mouseY/(height/8)]==0) tempBitmap[mouseX/(width/8)][mouseY/(height/8)]=1; else tempBitmap[mouseX/(width/8)][mouseY/(height/8)]=0; */ tempBitmap[mouseX/(width/8)][mouseY/(height/8)]=painter; for (byte i=0;i<8;i++) { if( tempBitmap[i][mouseY/(height/8)]==1) myByte= populateByteOn(myByte,i); } if (port!=null) { port.write("3"); port.write(mouseY/(height/8)); port.write(myByte); } } } void draw() { background(0); tjatjing(); if(mousePressed) { line(mouseX-66, mouseY, mouseX+66, mouseY); line(mouseX, mouseY-66, mouseX, mouseY+66); } for (int i=0;i<8;i++) for (int ii=0;ii<8;ii++) { if( tempBitmap[i][ii] ==0) fill(0,120,0); else fill(0,240,0); rect(i*width/8, ii*height/8, width/8-2, height/8-2); } } void stop() { port.stop(); println("stopped"); }