import cc.arduino.*; // Write data to the serial port according to the mouseX value import processing.serial.*; Arduino arduino; Serial port; // Create object from Serial class float mx = 0.0; float my = 0.0; String buffer; void setup() { size(600, 600); noStroke(); frameRate(30); // Open the port that the board is connected to and use the same speed (9600 bps) arduino = new Arduino(this, Arduino.list()[0], 115200); } void draw() { background(0); // Clear background float difX = mouseX - mx; if (abs(difX) > 1.0) { mx += difX / 4.0; } mx = constrain(mx, 50, width-50); // Keeps marker on the screen float difY = mouseY - my; if (abs(difY) > 1.0) { my += difY / 4.0; } my = constrain(my, 50, height-50); // Keeps marker on the screen noStroke(); fill(255); ellipse(mx,my, 30, 30); // Draw the position marker int angleX = int(map(mx, 50, width - 50, 0, 180)); // Scale the value the range 0-180 int angleY = int(map(my, 50, height - 50, 0, 180)); //print(angle + " "); // Print the current angle (debug) // Write the angle to the serial port arduino.analogWrite(9,angleX); arduino.analogWrite(10, angleY); }