import processing.serial.*;

//For serial communication
Serial myPort;
int byte1, byte2, byte3, byte4, high, low;
int value = 0;

void setup() {
  /*** Set this so it picks up your board ***/
  myPort = new Serial(this, Serial.list()[3], 9600);
  /*****/

  //size(640, 360);
  fullScreen();
}

void draw() {
  background(value); // Set background to black

  // Receive the data
  while ( myPort.available() > 0) {  // If data is available,
    byte1 = byte2;
    byte2 = byte3;
    byte3 = byte4;
    byte4 = low;
    low = high;
    high = myPort.read();

    if ((byte1 == 1) & (byte2 == 2) & (byte3 == 3) & (byte4 ==4)) {
      //Reset the preamble.
      byte1=byte2=byte3=byte4=0;
      value = ((256*high)+low);
      println("Counter is "+ value);
      value = value >> 2;
    }
  }
}
