// *** Processing code *** // scaled mouseX to serial // // Sending data to the Arduino //------------------------------- import processing.serial.*; int rectSize = 20; // Size of rectangle to track mouse int sendX = 1; // Variable for sending mouseX scaled Serial port; // Create place in memory for serial communication void setup() { size(250, 255); rectMode(CENTER); stroke(255); fill(153); println(Serial.list()); // print out available serial ports // Open the port that the Arduino board is connected to (in this case #0) // Make sure to open the port at the same speed Arduino is using (9600bps) port = new Serial(this, Serial.list()[1], 9600); } void draw() { background(0); rect(mouseX, 100, rectSize, rectSize); // Draw the box sendX = int(map(mouseX, 0, 255, 0, 10)); // scale so it sends 1-10 println(sendX); port.write(sendX); delay(10); } |