View difference between Paste ID: bpqE8B3x and Bpg4CCAf
SHOW: | | - or go back to the newest paste.
1
import processing.serial.*;
2
3
Serial myPort;  // Create object from Serial class
4
int val;     // Data received from the serial port
5
int valOld;
6
float[][] matrix;
7
8
9
10
void setup()
11
{
12
  // I know that the first port in the serial list on my mac
13
  // is Serial.list()[0].
14
  // On Windows machines, this generally opens COM1.
15
  // Open whatever port is the one you're using.
16
  String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
17
  myPort = new Serial(this, portName, 115200);
18
  matrix = new float[20][20];
19
  size(1000,1000);
20
  for(int i=0;i<16;i++){
21
      for(int j=0;j<12;j++){
22
         matrix[j][i]=0;
23
      }
24
  }
25
}
26
27
void draw()
28
{
29
  if (mousePressed == true) 
30
  {                           //if we clicked in the window
31
    myPort.write('1');         //send a 1
32
    println("1");   
33
  }     
34
  if ( myPort.available() > 0) 
35
  {  // If data is available,
36
    for(int i=0;i<12;i++){
37
      for(int j=0;j<16;j++){
38
        
39
        val= myPort.read();         // read it and store it in val
40
        matrix[j][i]=Integer.valueOf(val);
41
        //println(val);
42
        delay(10);
43
        if(myPort.read()==-1){
44
          break;
45
        }
46
      }
47
    }
48
  }
49
delay(10);
50
51
//if(val!=valOld){
52
//    for(int i=0;i<12;i++){
53
//      for(int j=0;j<16;j++){
54
//        print(matrix[j][i]); //print it out in the console
55
//        print('\t');
56
//      }
57
//    println();  
58
//  }
59
//valOld=val;
60
//}
61
  for(int i=0;i<12;i++){
62
    for(int j=0;j<16;j++){
63
     float x=i*120;
64
     float y=j*120;
65
     if(matrix[j][i]==49){
66
     fill(0,0,0);
67
     }
68
     else if(matrix[j][i]==51){
69
     fill(64,0,0);
70
     }
71
     else if(matrix[j][i]==52){
72
     fill(128,0,0);
73
     }
74
     else if(matrix[j][i]==53){
75
     fill(255,0,0);
76
     }
77
     ellipse(60+x,60+y,120,120);
78
     }
79
  }
80
81
}