Assignment 10.2

Post date: Aug 01, 2010 5:44:2 PM

Move your mouse to the right in the processing sketch, the LED gets bright. Move it to the left, it gets darker. Genius.

Also the background in processing gets brighter and darker along with the LED. I thought that was fun.


import processing.serial.*; //import all serial libraries

Serial serPort; // Create object from Serial class

void setup() {

size(600, 150);

serPort = new Serial(this, Serial.list()[0], 9600);


void draw() {

int briteness = int(map(mouseX, 0, 600, 0, 255)); //set variable relative to mouse X

serPort.write(briteness); //write value to serial

background(0, briteness, 0); //set background green to value

delay(50); //delay 50 ms so arduino can catch up



const int led1 = 9;

int brightness;

void setup() {



void loop() {

if (Serial.available() > 0) { //check if serial isn't empty

brightness =; //set varible to last byte in serial

analogWrite(led1, brightness); //write value to LED