How to change the value of graph?

edited September 2015 in Arduino

Hi there, Im using processing to control the birghtness of led with arduino. I already can control the brightness of led using mouse. But the problem is i want to change the value of graph so that the intersection of graph x and graph y is located in the middle. Below is the code that i used.

Processing Code

//Processing Code
 import processing.serial.*;
Serial myPort;
void setup()
{
size(255, 255);
String portName = Serial.list()[0]; // This gets the first port on your computer.
myPort = new Serial(this, portName, 9600);
}

void draw() {
// Create a gradient for visualisation
for (int i = 0; i<width; i++) {
for (int j = 0; j<height; j++) {
color myCol = color(i,j,0);
set(i, j, myCol);

}
}
// Send an event trigger character to indicate the beginning of the communication
myPort.write('S');
// Send the value of the mouse's x-position
myPort.write(mouseX);
// Send the value of the mouse's y-position
myPort.write(mouseY);
}

Arduino code

Arduino Code
int val, xVal, yVal;
void setup() {
Serial.begin(9600);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
void loop(){
// check if enough data has been sent from the computer:
if (Serial.available()>2) {
// Read the first value. This indicates the beginning of the communication.
val = Serial.read();
// If the value is the event trigger character 'S'
if(val == 'S'){
// read the most recent byte, which is the x-value
xVal = Serial.read();
// Then read the y-value
yVal = Serial.read();
}
}
// And send those to the LEDS!
analogWrite(10, xVal);
analogWrite(11, yVal);
}
Sign In or Register to comment.