I kind of made some code on
I kind of made some code on this subject
the processing part takes x position and y position of mouse and writes it to the port of the arduino.
heres processing code.
import processing.serial.*;
Serial port;
void setup() {
size(180, 180);
println(“Available serial ports:”);
println(Serial.list());
// Uses the first port in this list (number 0). Change this to
// select the port corresponding to your Arduino board. The last
// parameter (e.g. 9600) is the speed of the communication. It
// has to correspond to the value passed to Serial.begin() in your
// Arduino sketch.
port = new Serial(this, Serial.list()[0], 9600);
// If you know the name of the port used by the Arduino board, you
// can specify it directly like this.
//port = new Serial(this, “COM1”, 9600);
}
void draw() {
// draw a gradient from black to white
for (int i = 0; i < 180; i++) {
stroke(i);
line(i, 0, i, 180);
}
// write the current X-position of the mouse to the serial port as
// a single byte
port.write(mouseX);
port.write(",");
port.write(mouseY);
}
the x and y goes in this form 120,120
the arduino side kind of decodes it i think it uses serial.parseint got it here http://arduino.cc/en/Tutorial/ReadASCIIString
here is the adino code
#include <Servo.h>
Servo servo;
Servo servo1;
void setup()
{
// initialize the serial communication:
Serial.begin(9600);
servo.attach(9);
servo1.attach(10);
}
void loop() {
int brightness;
int brightness1;
// check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
int brightness = Serial.parseInt();
int brightness1 = Serial.parseInt();
// set the brightness of the LED:
servo.write(brightness);
servo1.write(brightness1);
}
}