This Max patch takes in serial data and graphs it. It’s useful for seeing the changes in an analog sensor. An Arduino code sample that works with it follows the patch.
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: serial
max v2; #N vpatcher 149 116 801 639; #P user multiSlider 312 313 246 167 0. 1023. 1 3433 47 0 0 2 0 0 0; #M frgb 17 15 198; #M brgb 59 182 255; #M rgb2 127 127 127; #M rgb3 0 0 0; #M rgb4 37 52 91; #M rgb5 74 105 182; #M rgb6 112 158 18; #M rgb7 149 211 110; #M rgb8 187 9 201; #M rgb9 224 62 37; #M rgb10 7 114 128; #P window setfont "Sans Serif" 9.; #P comment 327 138 191 196617 Click here to get a list of serial ports; #P comment 210 293 97 196617 Here's your value; #P comment 380 271 215 196617 Convert ASCII to symbol; #P comment 380 248 215 196617 Convert integer to ASCII; #P number 312 292 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P newex 312 271 62 196617 fromsymbol; #B color 5; #P newex 312 248 40 196617 itoa; #B color 5; #P newex 312 225 55 196617 zl group 4; #P newex 256 187 67 196617 select 10 13; #P toggle 256 94 15 0; #P newex 256 116 46 196617 metro 1; #P message 291 138 32 196617 print; #P newex 256 163 71 196617 serial a 9600; #P window linecount 2; #P comment 61 116 191 196617 Read serial input buffer every 10 milliseconds; #P window linecount 3; #P comment 329 187 215 196617 If you get newline (ASCII 10) , send the list. If you get return (ASCII 13) do nothing. Any other value , add to the list; #P window linecount 1; #P comment 283 94 100 196617 Click to start; #P connect 6 0 5 0; #P connect 5 0 3 0; #P fasten 4 0 3 0 296 158 261 158; #P connect 3 0 7 0; #P fasten 7 0 8 0 261 216 317 216; #P fasten 7 2 8 0 317 228 317 228; #P connect 8 0 9 0; #P connect 9 0 10 0; #P connect 10 0 11 0; #P connect 11 0 16 0; #P pop;
Arduino code that sends in an analog value in the appropriate format:
void setup() { Serial.begin(9600); } void loop() { int val = analogRead(0); Serial.println(val, DEC); delay(100); }