Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.serial.*;
- Serial myPort; // Create object from Serial class
- int val; // Data received from the serial port
- int valOld;
- float[][] matrix;
- void setup()
- {
- // I know that the first port in the serial list on my mac
- // is Serial.list()[0].
- // On Windows machines, this generally opens COM1.
- // Open whatever port is the one you're using.
- String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
- myPort = new Serial(this, portName, 115200);
- matrix = new float[20][20];
- size(1000,1000);
- for(int i=0;i<16;i++){
- for(int j=0;j<12;j++){
- matrix[j][i]=0;
- }
- }
- }
- void draw()
- {
- if (mousePressed == true)
- { //if we clicked in the window
- myPort.write('1'); //send a 1
- println("1");
- }
- if ( myPort.available() > 0)
- { // If data is available,
- for(int i=0;i<12;i++){
- for(int j=0;j<16;j++){
- val= myPort.read(); // read it and store it in val
- matrix[j][i]=Integer.valueOf(val);
- //println(val);
- delay(10);
- if(myPort.read()==-1){
- break;
- }
- }
- }
- }
- delay(10);
- //if(val!=valOld){
- // for(int i=0;i<12;i++){
- // for(int j=0;j<16;j++){
- // print(matrix[j][i]); //print it out in the console
- // print('\t');
- // }
- // println();
- // }
- //valOld=val;
- //}
- for(int i=0;i<12;i++){
- for(int j=0;j<16;j++){
- float x=i*120;
- float y=j*120;
- if(matrix[j][i]==49){
- fill(0,0,0);
- }
- else if(matrix[j][i]==51){
- fill(64,0,0);
- }
- else if(matrix[j][i]==52){
- fill(128,0,0);
- }
- else if(matrix[j][i]==53){
- fill(255,0,0);
- }
- ellipse(60+x,60+y,120,120);
- }
- }
- }
Add Comment
Please, Sign In to add comment