/* Based on code written by If you want you may contact me at seabre986@gmail.com or on reddit: seabre Modications made by Oliver Smith to print out buttons and control lighting http://chemicaloliver.net */ import processing.serial.*; //Horizontal coordinate for graphics int xPos = 1; //Take what we know about the packets for starting the access point //and put it in its integer representation int startAccessPointNum[] = {255, 7, 3}; //Take what we know about the packets for aquiring data from the chronos //and put it in its integer representation int accDataRequestNum[] = {255, 8, 7, 0, 0, 0, 0}; //Convert it all to bytes so that watch will understand //what we're talking about.. byte startAccessPoint[] = byte(startAccessPointNum); byte accDataRequest[] = byte(accDataRequestNum); // We want to talk to the chronos... Serial chronos; Serial arduino; void setup() { //Draw window //In linux /dev/ttyACM0 is not correctly detected by java so //setting this property solves that //You'll need to change this if you are using osx/windows or //another serial port System.setProperty("gnu.io.rxtx.SerialPorts", "/dev/ttyACM3"); chronos = new Serial(this, "/dev/ttyACM3", 115200); //Setup serial port for arduino System.setProperty("gnu.io.rxtx.SerialPorts", "/dev/ttyUSB0"); arduino = new Serial(this, "/dev/ttyUSB0",9600); //Start the access point.. chronos.write(startAccessPoint); //Until the port is still availible... //Send data request to chronos. chronos.write(accDataRequest); background(0); } void draw() { if(chronos.available() >= 0) { //Accelerometer data is 7 bytes long. This looks really lame, but it works. int[] buf = new int[7]; for (int i = 0; i < 7; i++) buf[i] = chronos.read(); //Fourth byte indicates if there are coordinates. If the byte is 0xFF (255) //Then there is no data. If it is 1, then data is valid. //Sometimes the datatype comes back as other values...not sure if that //means anything or not. //Also, the Python version of this code ALWAYS returns 0xFF (255).. //Don't know why that is. if(buf[4] == 0) { /*for (int i = 0; i < 7; i++) { print (i+" = "+buf[i]+" "); } println("\n");*/ //on my chronos (the 868MHz version) the following values are correct however other watches may use //values one less than the current value if(buf[3]==18) { println("Top Left"); } if(buf[3]==50) { println("Top Right"); //Send on signal arduino.write('H'); } if(buf[3]==34) { println("Bottom Left"); //Send off signal arduino.write('L'); } } } chronos.write(accDataRequest); }