Analog to Frequency for Max/MSP

This Max/MSP patch takes a serial string in and converts it to a numeric value, then plays a frequency using the value.

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: ,



analogtofrequency.png

max v2;
#N vpatcher 193 214 742 698;
#P user multiSlider 299 322 125 91 0. 1023. 1 3449 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 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 278 81 191 196617 Click here to get a list of serial ports;
#P comment 144 236 112 196617 Here's your frequency;
#P comment 331 214 215 196617 Convert ASCII to symbol;
#P comment 331 191 215 196617 Convert integer to ASCII;
#P number 263 235 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 263 214 62 196617 fromsymbol;
#B color 5;
#P newex 263 191 40 196617 itoa;
#B color 5;
#P newex 263 168 55 196617 zl group 4;
#P newex 207 130 67 196617 select 10 13;
#P toggle 207 37 15 0;
#P newex 207 59 52 196617 metro 10;
#P message 242 81 32 196617 print;
#P newex 207 106 71 196617 serial a 9600;
#P window linecount 2;
#P comment 12 59 191 196617 Read serial input buffer every 10 milliseconds;
#P window linecount 3;
#P comment 280 130 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 234 37 100 196617 Click to start;
#P comment 60 255 196 196617 digital-to-analog converter makes sounds;
#P comment 363 276 215 196617 Click to stop frequency generator;
#P comment 363 255 215 196617 Click to start frequency generator;
#P message 330 276 29 196617 stop;
#P message 321 255 33 196617 start;
#P newex 263 299 31 196617 dac~;
#P newex 263 255 40 196617 cycle~;
#P connect 13 0 12 0;
#P fasten 11 0 10 0 247 101 212 101;
#P connect 12 0 10 0;
#P connect 10 0 14 0;
#P fasten 14 2 15 0 268 171 268 171;
#P fasten 14 0 15 0 212 159 268 159;
#P connect 15 0 16 0;
#P connect 16 0 17 0;
#P connect 17 0 18 0;
#P connect 18 0 0 0;
#P connect 0 0 1 0;
#P fasten 2 0 1 0 326 284 268 284;
#P fasten 3 0 1 0 335 295 268 295;
#P fasten 18 0 23 0 268 280 304 280;
#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);
}