// 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 < 256; i++) {
stroke(i);
line(i, 0, i, 150);
}
// write the current X-position of the mouse to the serial port as
// a single byte
port.write(mouseX);
}
*/
/* Max/MSP v5 patch for this example
{
"boxes" : [ {
"box" : {
"maxclass" : "comment",
"text" : "Dimmer\n\nThis patch sends a binary number from 0 to 255 out the serial port to an Arduino connected to the port. It dims an LED attached to the Arduino.\n\ncreated 2006\nby David A. Mellis\nmodified 14 Apr 2009\nby Scott Fitzgerald and Tom Igoe",
"linecount" : 10,
"patching_rect" : [ 209.0, 55.0, 344.0, 144.0 ],
"numoutlets" : 0,
"fontsize" : 12.0,
"id" : "obj-32",
"fontname" : "Arial",
"numinlets" : 1
}
}
, {
"box" : {
"maxclass" : "comment",
"text" : "change the slider to alter the brightness of the LED",
"linecount" : 3,
"patching_rect" : [ 90.0, 235.0, 117.0, 48.0 ],
"numoutlets" : 0,
"fontsize" : 12.0,
"id" : "obj-7",
"fontname" : "Arial",
"numinlets" : 1
}
}
, {
"box" : {
"maxclass" : "number",
"patching_rect" : [ 215.0, 385.0, 50.0, 19.0 ],
"numoutlets" : 2,
"fontsize" : 10.0,
"outlettype" : [ "int", "bang" ],
"id" : "obj-6",
"fontname" : "Verdana",
"numinlets" : 1
}
}
, {
"box" : {
"maxclass" : "slider",
"patching_rect" : [ 215.0, 235.0, 20.0, 140.0 ],
"numoutlets" : 1,
"outlettype" : [ "" ],
"bgcolor" : [ 0.94902, 0.94902, 0.94902, 0.0 ],
"id" : "obj-1",
"size" : 256.0,
"numinlets" : 1
}
}
, {
"box" : {
"maxclass" : "newobj",
"text" : "select 0 1",
"patching_rect" : [ 342.0, 305.0, 62.0, 20.0 ],
"numoutlets" : 3,
"fontsize" : 12.0,
"outlettype" : [ "bang", "bang", "" ],
"id" : "obj-30",
"fontname" : "Arial",
"numinlets" : 1
}
}
, {
"box" : {
"maxclass" : "comment",
"text" : "click here to close the serial port",
"patching_rect" : [ 390.0, 396.0, 206.0, 20.0 ],
"numoutlets" : 0,
"fontsize" : 12.0,
"id" : "obj-26",
"fontname" : "Arial",
"numinlets" : 1
}
}
, {
"box" : {
"maxclass" : "comment",
"text" : "click here to open the serial port",
"patching_rect" : [ 415.0, 370.0, 206.0, 20.0 ],
"numoutlets" : 0,
"fontsize" : 12.0,
"id" : "obj-27",
"fontname" : "Arial",
"numinlets" : 1
}
}
, {
"box" : {
"maxclass" : "message",
"text" : "close",
"patching_rect" : [ 342.0, 396.0, 39.0, 18.0 ],
"numoutlets" : 1,
"fontsize" : 12.0,
"outlettype" : [ "" ],
"id" : "obj-21",
"fontname" : "Arial",
"numinlets" : 2
}
}
, {
"box" : {
"maxclass" : "message",
"text" : "port a",
"patching_rect" : [ 364.0, 370.0, 41.0, 18.0 ],
"numoutlets" : 1,
"fontsize" : 12.0,
"outlettype" : [ "" ],
"id" : "obj-19",
"fontname" : "Arial",
"numinlets" : 2
}
}
, {
"box" : {
"maxclass" : "comment",
"text" : "Click here to get a list of serial ports",