This Max/MSP patch sends data out the serial port. The corresponding Arduino program reads the data from Max serially and uses it to set the brightness of an LED on digital pin 9.
To use the patch, copy the text and paste it into a new max patch window.
Thanks to David Mellis and Jamie Allen for the collaboration. These patches were written for a one-day Arduino workshop at NIME 07 hosted by the three of us. The Arduino program comes from the Arduino example files, by David Mellis.
Technorati Tags: arduino, pcomp, physical computing
max v2; #N vpatcher 300 241 617 515; #P user uslider 150 38 18 128 255 1 0 0; #P window setfont "Sans Serif" 9.; #P window linecount 1; #P message 76 164 32 196617 print; #P newex 150 189 71 196617 serial a 9600; #P window linecount 2; #P comment 180 120 100 196617 Slide the fader to dim the LED; #P comment 12 131 125 196617 Click here to get a list of serial ports; #P fasten 3 0 2 0 81 184 155 184; #P fasten 4 0 2 0 155 187 155 187; #P pop;
Arduino code
int ledPin = 9; void setup() { // begin the serial communication Serial.begin(9600); pinMode(ledPin, OUTPUT); } void loop() { byte val; // check if data has been sent from the computer if (Serial.available()) { // read the most recent byte (which will be from 0 to 255) val = Serial.read(); // set the brightness of the LED analogWrite(ledPin, val); } }