Wednesday, September 22, 2010

Rough Noise Sketch


float inc = 0.008;
int density = 4;
float znoise = 0.0;

void setup() {
size(720, 480);
noStroke();
}

void draw() {
float xnoise = 0.0;
float ynoise = 0.0;
for (int y = 0; y < width; y += density) {
for (int x = 0; x < height; x += density) {
float n = noise(xnoise, ynoise, znoise) * 200;
//noise(x, y, z);
if (mouseX>360) {
fill(n+mouseY); }
else {
fill(n); }
rect(y, x, density, density);
xnoise += inc;
}
xnoise = 0;
ynoise += inc;
}
znoise +=inc;
}

Sparkfun Electronics

http://www.sparkfun.com

Tuesday, September 21, 2010

Light Into Sound!

Alex and Matthew perform their custom-built Phototheremins...

Monday, September 20, 2010

Arduino Sketch, Phototheremin





//Example 07: Send to the computer the values read from
//analogue input 0
//Make sure you click on "Serial Monitor"
//after you upload

#define SENSOR 0 // select the input pin for the
// sensor resistor
const int numReadings = 10;

//int val = 0; //variable to store the value coming from the sensor
int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average

int inputPin = SENSOR;


void setup() {

Serial.begin(9600); // open the serial port to send data back to the computer
// at 9600 bits per second
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;

}

void loop() {

// subtract the last reading:
total= total - readings[index];
// read from the sensor:
readings[index] = analogRead(inputPin);
// add the reading to the total:
total= total + readings[index];
// advance to the next position in the array:
index = index + 1;

// if we're at the end of the array...
if (index >= numReadings)
// ...wrap around to the beginning:
index = 0;

// calculate the average:
average = total / numReadings;
// send it to the computer (as ASCII digits)

//val = analogRead(SENSOR); //read the value from the sensor

Serial.println(average, DEC); //print the value to the serial port

//delay (10); // wait 10 ms between each send
}

Max Patch Part 2, for Phototheremin




{
"boxes" : [ {
"box" : {
"maxclass" : "newobj",
"text" : "select 0 1",
"numinlets" : 1,
"numoutlets" : 3,
"patching_rect" : [ 296.0, 45.0, 62.0, 20.0 ],
"fontname" : "Arial",
"id" : "obj-30",
"outlettype" : [ "bang", "bang", "" ],
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "close",
"numinlets" : 2,
"numoutlets" : 1,
"patching_rect" : [ 278.0, 77.0, 39.0, 18.0 ],
"fontname" : "Arial",
"id" : "obj-25",
"outlettype" : [ "" ],
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "port a",
"numinlets" : 2,
"numoutlets" : 1,
"patching_rect" : [ 339.0, 76.0, 41.0, 18.0 ],
"fontname" : "Arial",
"id" : "obj-26",
"outlettype" : [ "" ],
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "multislider",
"numinlets" : 1,
"candicane5" : [ 0.584314, 0.827451, 0.431373, 1.0 ],
"numoutlets" : 2,
"candicane4" : [ 0.439216, 0.619608, 0.070588, 1.0 ],
"patching_rect" : [ 378.0, 363.0, 125.0, 91.0 ],
"id" : "obj-1",
"setminmax" : [ 0.0, 1023.0 ],
"peakcolor" : [ 0.498039, 0.498039, 0.498039, 1.0 ],
"outlettype" : [ "", "" ],
"candicane3" : [ 0.290196, 0.411765, 0.713726, 1.0 ],
"candicane8" : [ 0.027451, 0.447059, 0.501961, 1.0 ],
"setstyle" : 3,
"candicane2" : [ 0.145098, 0.203922, 0.356863, 1.0 ],
"candicane7" : [ 0.878431, 0.243137, 0.145098, 1.0 ],
"candicane6" : [ 0.733333, 0.035294, 0.788235, 1.0 ]
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "Click here to get a list of serial ports",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 327.0, 138.0, 191.0, 17.0 ],
"fontname" : "Arial",
"id" : "obj-2",
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "Here's your frequency",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 193.0, 293.0, 112.0, 17.0 ],
"fontname" : "Arial",
"id" : "obj-3",
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "Convert ASCII to symbol",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 380.0, 271.0, 215.0, 17.0 ],
"fontname" : "Arial",
"id" : "obj-4",
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "Convert integer to ASCII",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 380.0, 248.0, 215.0, 17.0 ],
"fontname" : "Arial",
"id" : "obj-5",
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "number",
"numinlets" : 1,
"htextcolor" : [ 0.870588, 0.870588, 0.870588, 1.0 ],
"numoutlets" : 2,
"patching_rect" : [ 312.0, 292.0, 35.0, 17.0 ],
"fontname" : "Arial",
"id" : "obj-6",
"outlettype" : [ "int", "bang" ],
"bgcolor" : [ 0.866667, 0.866667, 0.866667, 1.0 ],
"fontsize" : 9.0,
"triscale" : 0.9
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "fromsymbol",
"numinlets" : 1,
"color" : [ 1.0, 0.890196, 0.090196, 1.0 ],
"numoutlets" : 1,
"patching_rect" : [ 312.0, 271.0, 62.0, 17.0 ],
"fontname" : "Arial",
"id" : "obj-7",
"outlettype" : [ "" ],
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "itoa",
"numinlets" : 3,
"color" : [ 1.0, 0.890196, 0.090196, 1.0 ],
"numoutlets" : 1,
"patching_rect" : [ 312.0, 248.0, 40.0, 17.0 ],
"fontname" : "Arial",
"id" : "obj-8",
"outlettype" : [ "int" ],
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "zl group 4",
"numinlets" : 2,
"numoutlets" : 2,
"patching_rect" : [ 312.0, 225.0, 55.0, 17.0 ],
"fontname" : "Arial",
"id" : "obj-9",
"outlettype" : [ "", "" ],
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "select 10 13",
"numinlets" : 1,
"numoutlets" : 3,
"patching_rect" : [ 256.0, 187.0, 67.0, 17.0 ],
"fontname" : "Arial",
"id" : "obj-10",
"outlettype" : [ "bang", "bang", "" ],
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "toggle",
"numinlets" : 1,
"numoutlets" : 1,
"patching_rect" : [ 256.0, 11.0, 15.0, 15.0 ],
"id" : "obj-11",
"outlettype" : [ "int" ]
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "metro 10",
"numinlets" : 2,
"numoutlets" : 1,
"patching_rect" : [ 222.0, 78.0, 52.0, 17.0 ],
"fontname" : "Arial",
"id" : "obj-12",
"outlettype" : [ "bang" ],
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "print",
"numinlets" : 2,
"numoutlets" : 1,
"patching_rect" : [ 291.0, 138.0, 32.0, 15.0 ],
"fontname" : "Arial",
"id" : "obj-13",
"outlettype" : [ "" ],
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "serial a 9600",
"numinlets" : 1,
"numoutlets" : 2,
"patching_rect" : [ 256.0, 163.0, 71.0, 17.0 ],
"fontname" : "Arial",
"id" : "obj-14",
"outlettype" : [ "int", "" ],
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "Read serial input buffer every 10 milliseconds",
"linecount" : 2,
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 61.0, 116.0, 189.0, 27.0 ],
"fontname" : "Arial",
"id" : "obj-15",
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "If you get newline (ASCII 10), send the list. If you get return (ASCII 13) do nothing. Any other value, add to the list",
"linecount" : 3,
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 329.0, 187.0, 215.0, 38.0 ],
"fontname" : "Arial",
"id" : "obj-16",
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "Click to start",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 275.0, 12.0, 100.0, 17.0 ],
"fontname" : "Arial",
"id" : "obj-17",
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "digital-to-analog converter makes sounds",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 109.0, 312.0, 196.0, 17.0 ],
"fontname" : "Arial",
"id" : "obj-18",
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "Click to stop frequency generator",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 412.0, 333.0, 215.0, 17.0 ],
"fontname" : "Arial",
"id" : "obj-19",
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "Click to start frequency generator",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 412.0, 312.0, 215.0, 17.0 ],
"fontname" : "Arial",
"id" : "obj-20",
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "stop",
"numinlets" : 2,
"numoutlets" : 1,
"patching_rect" : [ 379.0, 333.0, 29.0, 15.0 ],
"fontname" : "Arial",
"id" : "obj-21",
"outlettype" : [ "" ],
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "start",
"numinlets" : 2,
"numoutlets" : 1,
"patching_rect" : [ 370.0, 312.0, 33.0, 15.0 ],
"fontname" : "Arial",
"id" : "obj-22",
"outlettype" : [ "" ],
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "dac~",
"numinlets" : 2,
"numoutlets" : 0,
"patching_rect" : [ 312.0, 356.0, 31.0, 17.0 ],
"fontname" : "Arial",
"id" : "obj-23",
"fontsize" : 9.0
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "cycle~",
"numinlets" : 2,
"numoutlets" : 1,
"patching_rect" : [ 312.0, 312.0, 40.0, 17.0 ],
"fontname" : "Arial",
"id" : "obj-24",
"outlettype" : [ "signal" ],
"fontsize" : 9.0
}

}
],
"lines" : [ {
"patchline" : {
"source" : [ "obj-26", 0 ],
"destination" : [ "obj-14", 0 ],
"hidden" : 0,
"midpoints" : [ 348.5, 128.0, 265.5, 128.0 ]
}

}
, {
"patchline" : {
"source" : [ "obj-25", 0 ],
"destination" : [ "obj-14", 0 ],
"hidden" : 0,
"midpoints" : [ 287.5, 128.5, 265.5, 128.5 ]
}

}
, {
"patchline" : {
"source" : [ "obj-11", 0 ],
"destination" : [ "obj-30", 0 ],
"hidden" : 0,
"midpoints" : [ 265.0, 35.0, 305.5, 35.0 ]
}

}
, {
"patchline" : {
"source" : [ "obj-30", 0 ],
"destination" : [ "obj-25", 0 ],
"hidden" : 0,
"midpoints" : [ 305.5, 70.5, 287.5, 70.5 ]
}

}
, {
"patchline" : {
"source" : [ "obj-30", 1 ],
"destination" : [ "obj-26", 0 ],
"hidden" : 0,
"midpoints" : [ 327.0, 70.0, 348.5, 70.0 ]
}

}
, {
"patchline" : {
"source" : [ "obj-11", 0 ],
"destination" : [ "obj-12", 0 ],
"hidden" : 0,
"midpoints" : [ 265.0, 51.5, 231.5, 51.5 ]
}

}
, {
"patchline" : {
"source" : [ "obj-12", 0 ],
"destination" : [ "obj-14", 0 ],
"hidden" : 0,
"midpoints" : [ 231.5, 128.5, 265.5, 128.5 ]
}

}
, {
"patchline" : {
"source" : [ "obj-13", 0 ],
"destination" : [ "obj-14", 0 ],
"hidden" : 0,
"midpoints" : [ 300.5, 158.0, 265.5, 158.0 ]
}

}
, {
"patchline" : {
"source" : [ "obj-14", 0 ],
"destination" : [ "obj-10", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-10", 0 ],
"destination" : [ "obj-9", 0 ],
"hidden" : 0,
"midpoints" : [ 265.5, 216.0, 321.5, 216.0 ]
}

}
, {
"patchline" : {
"source" : [ "obj-10", 2 ],
"destination" : [ "obj-9", 0 ],
"hidden" : 0,
"midpoints" : [ 313.5, 228.0, 321.5, 228.0 ]
}

}
, {
"patchline" : {
"source" : [ "obj-9", 0 ],
"destination" : [ "obj-8", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-8", 0 ],
"destination" : [ "obj-7", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-7", 0 ],
"destination" : [ "obj-6", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-6", 0 ],
"destination" : [ "obj-24", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-21", 0 ],
"destination" : [ "obj-23", 0 ],
"hidden" : 0,
"midpoints" : [ 388.5, 352.0, 321.5, 352.0 ]
}

}
, {
"patchline" : {
"source" : [ "obj-22", 0 ],
"destination" : [ "obj-23", 0 ],
"hidden" : 0,
"midpoints" : [ 379.5, 341.0, 321.5, 341.0 ]
}

}
, {
"patchline" : {
"source" : [ "obj-24", 0 ],
"destination" : [ "obj-23", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-6", 0 ],
"destination" : [ "obj-1", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
]
}

Wednesday, September 15, 2010

Max Waves: A Theremin?




{
"boxes" : [ {
"box" : {
"maxclass" : "newobj",
"text" : "loadmess 1",
"numinlets" : 1,
"numoutlets" : 1,
"patching_rect" : [ 198.0, 132.0, 72.0, 20.0 ],
"fontname" : "Arial",
"id" : "obj-10",
"outlettype" : [ "" ],
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "*~",
"numinlets" : 2,
"numoutlets" : 1,
"patching_rect" : [ 145.0, 200.0, 32.5, 20.0 ],
"fontname" : "Arial",
"id" : "obj-5",
"outlettype" : [ "signal" ],
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "flonum",
"numinlets" : 1,
"numoutlets" : 2,
"patching_rect" : [ 198.0, 161.0, 50.0, 20.0 ],
"fontname" : "Arial",
"id" : "obj-4",
"outlettype" : [ "float", "bang" ],
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "ezdac~",
"numinlets" : 2,
"numoutlets" : 0,
"patching_rect" : [ 145.0, 261.0, 45.0, 45.0 ],
"id" : "obj-2"
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "a MAX Theremin?",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 24.0, 33.0, 150.0, 18.0 ],
"fontname" : "Arial",
"id" : "obj-9",
"fontsize" : 10.0
}

}
, {
"box" : {
"maxclass" : "number",
"numinlets" : 1,
"numoutlets" : 2,
"patching_rect" : [ 145.0, 70.0, 50.0, 18.0 ],
"fontname" : "Arial",
"id" : "obj-8",
"outlettype" : [ "int", "bang" ],
"fontsize" : 10.0
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "* 4",
"numinlets" : 2,
"numoutlets" : 1,
"patching_rect" : [ 145.0, 108.0, 32.5, 18.0 ],
"fontname" : "Arial",
"id" : "obj-7",
"outlettype" : [ "int" ],
"fontsize" : 10.0
}

}
, {
"box" : {
"maxclass" : "number",
"numinlets" : 1,
"numoutlets" : 2,
"patching_rect" : [ 145.0, 132.0, 50.0, 18.0 ],
"fontname" : "Arial",
"id" : "obj-6",
"outlettype" : [ "int", "bang" ],
"fontsize" : 10.0
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "cycle~",
"numinlets" : 2,
"color" : [ 1.0, 0.890196, 0.090196, 1.0 ],
"numoutlets" : 1,
"patching_rect" : [ 145.0, 161.0, 44.0, 20.0 ],
"fontname" : "Arial",
"id" : "obj-1",
"outlettype" : [ "signal" ],
"fontsize" : 11.595187
}

}
],
"lines" : [ {
"patchline" : {
"source" : [ "obj-10", 0 ],
"destination" : [ "obj-4", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-4", 0 ],
"destination" : [ "obj-5", 1 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-5", 0 ],
"destination" : [ "obj-2", 1 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-5", 0 ],
"destination" : [ "obj-2", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-1", 0 ],
"destination" : [ "obj-5", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-6", 0 ],
"destination" : [ "obj-1", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-8", 0 ],
"destination" : [ "obj-7", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-7", 0 ],
"destination" : [ "obj-6", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
]
}

Monday, September 13, 2010

Another Control System: Max




{
"boxes" : [ {
"box" : {
"maxclass" : "comment",
"text" : "change the slider to alter the brightness of the LED",
"linecount" : 3,
"numinlets" : 1,
"patching_rect" : [ 14.0, 57.0, 117.0, 48.0 ],
"id" : "obj-7",
"fontname" : "Arial",
"numoutlets" : 0,
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "number",
"numinlets" : 1,
"patching_rect" : [ 139.0, 207.0, 50.0, 19.0 ],
"id" : "obj-6",
"fontname" : "Verdana",
"numoutlets" : 2,
"outlettype" : [ "int", "bang" ],
"fontsize" : 10.0
}

}
, {
"box" : {
"maxclass" : "slider",
"bgcolor" : [ 0.94902, 0.94902, 0.94902, 0.0 ],
"numinlets" : 1,
"patching_rect" : [ 139.0, 57.0, 20.0, 140.0 ],
"id" : "obj-1",
"numoutlets" : 1,
"size" : 256.0,
"outlettype" : [ "" ]
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "select 0 1",
"numinlets" : 1,
"patching_rect" : [ 266.0, 127.0, 62.0, 20.0 ],
"id" : "obj-30",
"fontname" : "Arial",
"numoutlets" : 3,
"outlettype" : [ "bang", "bang", "" ],
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "click here to close the serial port",
"numinlets" : 1,
"patching_rect" : [ 314.0, 218.0, 206.0, 20.0 ],
"id" : "obj-26",
"fontname" : "Arial",
"numoutlets" : 0,
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "click here to open the serial port",
"numinlets" : 1,
"patching_rect" : [ 339.0, 192.0, 206.0, 20.0 ],
"id" : "obj-27",
"fontname" : "Arial",
"numoutlets" : 0,
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "close",
"numinlets" : 2,
"patching_rect" : [ 266.0, 218.0, 39.0, 18.0 ],
"id" : "obj-21",
"fontname" : "Arial",
"numoutlets" : 1,
"outlettype" : [ "" ],
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "port a",
"numinlets" : 2,
"patching_rect" : [ 288.0, 192.0, 41.0, 18.0 ],
"id" : "obj-19",
"fontname" : "Arial",
"numoutlets" : 1,
"outlettype" : [ "" ],
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "Click here to get a list of serial ports",
"numinlets" : 1,
"patching_rect" : [ 359.0, 166.0, 207.0, 20.0 ],
"id" : "obj-2",
"fontname" : "Arial",
"numoutlets" : 0,
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "toggle",
"numinlets" : 1,
"patching_rect" : [ 266.0, 90.0, 15.0, 15.0 ],
"id" : "obj-11",
"numoutlets" : 1,
"outlettype" : [ "int" ]
}

}
, {
"box" : {
"maxclass" : "message",
"text" : "print",
"numinlets" : 2,
"patching_rect" : [ 308.0, 166.0, 36.0, 18.0 ],
"id" : "obj-13",
"fontname" : "Arial",
"numoutlets" : 1,
"outlettype" : [ "" ],
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "newobj",
"text" : "serial a 9600",
"numinlets" : 1,
"patching_rect" : [ 183.0, 242.0, 84.0, 20.0 ],
"id" : "obj-14",
"fontname" : "Arial",
"numoutlets" : 2,
"outlettype" : [ "int", "" ],
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "comment",
"text" : "Click to start",
"numinlets" : 1,
"patching_rect" : [ 293.0, 90.0, 117.0, 20.0 ],
"id" : "obj-17",
"fontname" : "Arial",
"numoutlets" : 0,
"fontsize" : 12.0
}

}
, {
"box" : {
"maxclass" : "panel",
"mode" : 1,
"numinlets" : 1,
"patching_rect" : [ 139.0, 57.0, 21.0, 139.0 ],
"grad1" : [ 1.0, 1.0, 1.0, 1.0 ],
"id" : "obj-8",
"numoutlets" : 0,
"angle" : 270.0,
"grad2" : [ 0.509804, 0.509804, 0.509804, 1.0 ]
}

}
],
"lines" : [ {
"patchline" : {
"source" : [ "obj-6", 0 ],
"destination" : [ "obj-14", 0 ],
"hidden" : 0,
"midpoints" : [ 148.5, 233.5, 192.5, 233.5 ]
}

}
, {
"patchline" : {
"source" : [ "obj-1", 0 ],
"destination" : [ "obj-6", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-13", 0 ],
"destination" : [ "obj-14", 0 ],
"hidden" : 0,
"midpoints" : [ 317.5, 187.5, 192.5, 187.5 ]
}

}
, {
"patchline" : {
"source" : [ "obj-19", 0 ],
"destination" : [ "obj-14", 0 ],
"hidden" : 0,
"midpoints" : [ 297.5, 215.5, 192.5, 215.5 ]
}

}
, {
"patchline" : {
"source" : [ "obj-21", 0 ],
"destination" : [ "obj-14", 0 ],
"hidden" : 0,
"midpoints" : [ 275.5, 238.5, 192.5, 238.5 ]
}

}
, {
"patchline" : {
"source" : [ "obj-30", 0 ],
"destination" : [ "obj-21", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-30", 1 ],
"destination" : [ "obj-19", 0 ],
"hidden" : 0,
"midpoints" : [ ]
}

}
, {
"patchline" : {
"source" : [ "obj-11", 0 ],
"destination" : [ "obj-30", 0 ],
"hidden" : 0,
"midpoints" : [ 275.0, 118.0, 275.5, 118.0 ]
}

}
]
}

Dim by degrees...


 

import processing.serial.*;
Serial port;

void setup() {
size(256, 150);

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 < 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);
}


Dim by degrees...


//degrees of 0 to 255, LED attached to digital pin 9 and ground
const int ledPin = 9;      // the pin that the LED is attached to  void setup() {   // initialize the serial communication:   Serial.begin(9600);   // initialize the ledPin as an output:   pinMode(ledPin, OUTPUT); }  void loop() {   byte brightness;    // check if data has been sent from the computer:   if (Serial.available()) {     // read the most recent byte (which will be from 0 to 255):     brightness = Serial.read();     // set the brightness of the LED:     analogWrite(ledPin, brightness);   } }

Wednesday, September 8, 2010

Processing-Arduino 1: Mouse to LED






Processing-Arduino 1: Mouse to LED

import processing.serial.*;

Serial port; //create object from "serial" class

void setup() {
size(200, 200);
noStroke();
frameRate(10);
//open the port that the board is connected to and use the same speed (9600bps)
port = new Serial(this, Serial.list()[0], 9600);
}

void draw() {
background(255);
if (mouseOverRect() == true) {
fill(204);
port.write("H");
} else {
fill(0);
port.write("L");
}
rect(50, 50, 100, 100);
}

boolean mouseOverRect() {
return((mouseX >= 50) && (mouseX <= 150) && (mouseY >=50) && (mouseY <= 150));
}

Hello World: Blink an LED with Arduino


#define LED 13

void setup() {
pinMode(LED, OUTPUT);
}

void loop()
{
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(100);
}