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