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
// Send the value of the mouse's x-position
// Send the value of the mouse's y-position

Arduino code

Arduino Code
int val, xVal, yVal;
void setup() {
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 =;
// If the value is the event trigger character 'S'
if(val == 'S'){
// read the most recent byte, which is the x-value
xVal =;
// Then read the y-value
yVal =;
// And send those to the LEDS!
analogWrite(10, xVal);
analogWrite(11, yVal);
Sign In or Register to comment.