max v2; #N vpatcher 77 44 1447 821; #P origin 187 -112; #P window setfont "Sans Serif" 9.; #N vpatcher 10 59 731 550; #P origin 0 391; #P window setfont "Sans Serif" 9.; #P comment 86 -310 490 196617 serial port } } } void sendValue (int x){ // function to send the pin value followed by a "space". Serial.print(x) \; Serial.print(32 \, BYTE) \; }; #P pop; #P newobj 244 87 77 196617 p arduino_code; #P comment 464 144 33 196617 nudge; #P button 473 172 16 5; #P window setfont "American Typewriter" 14.; #P comment 1022 584 21 199491598 5; #P comment 1022 490 21 199491598 4; #P comment 1022 391 21 199491598 3; #P comment 1022 278 21 199491598 2; #P comment 1022 179 21 199491598 1; #P user multiSlider 843 101 175 64 0. 1027. 1 3177 15 0 0 2 0 0 1; #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 user multiSlider 843 179 175 64 0. 1027. 1 3177 15 0 0 2 0 0 1; #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 user multiSlider 843 278 175 64 0. 1027. 1 3177 15 0 0 2 0 0 1; #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 user multiSlider 843 390 175 64 0. 1027. 1 3177 15 0 0 2 0 0 1; #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 user multiSlider 843 489 175 64 0. 1027. 1 3177 15 0 0 2 0 0 1; #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 user multiSlider 843 583 175 64 0. 1027. 1 3177 15 0 0 2 0 0 1; #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 36 92 201 196617 v0.03 Revised R Hoadley September 2008; #P number 712 517 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P button 548 377 15 0; #P number 667 322 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P newex 548 346 129 196617 if $i1 > $i2 then out1 bang; #P comment 36 77 72 196617 Feb 2007; #P window setfont "American Typewriter" 18.; #P comment 36 49 174 199491602 ArduinoToMax002; #P user panel 21 35 559 75; #X brgb 231 231 231; #X frgb 0 0 0; #X border 0; #X rounded 0; #X shadow 0; #X done; #P button 315 170 16 5; #P window setfont "Sans Serif" 9.; #P comment 310 144 35 196617 help; #P window linecount 4; #P comment 34 466 121 196617 To use the Arduino's digital pins as input \, make a recieve object as shown at right.; #P comment 36 317 121 196617 To use the Arduino's analog pins as inputs \, make a receive object as shown at right.; #P window linecount 8; #P comment 37 136 121 196617 Copy the block at right into your patch. (it does the work of reading the Arduino's pins) Connect the programmed Arduino \, and then click "start". Click on help for more info.; #P window linecount 1; #P newex 409 299 29 196617 r a4; #P newex 454 299 29 196617 r a5; #P newex 366 299 29 196617 r a3; #P newex 322 299 29 196617 r a2; #P newex 278 299 29 196617 r a1; #P newex 233 299 29 196617 r a0; #P newex 603 454 35 196617 r d12; #P newex 646 454 35 196617 r d13; #P newex 560 454 35 196617 r d11; #P newex 518 454 35 196617 r d10; #P newex 481 454 29 196617 r d9; #P newex 445 454 29 196617 r d8; #P newex 374 454 29 196617 r d6; #P newex 409 454 29 196617 r d7; #P newex 338 454 29 196617 r d5; #P newex 303 454 29 196617 r d4; #P newex 269 454 29 196617 r d3; #P newex 236 454 29 196617 r d2; #P window setfont Verdana 12.; #P comment 256 539 223 -1006632948 Reading the Arduino's digital pins; #P button 394 172 16 5; #P user led 236 513 17 17 3 150; #P user led 646 514 17 17 3 150; #P user led 603 513 17 17 3 150; #P user led 560 513 17 17 3 150; #P user led 518 513 17 17 3 150; #P user led 481 513 17 17 3 150; #P user led 445 513 17 17 3 150; #P user led 409 513 17 17 3 150; #P user led 374 513 17 17 3 150; #P user led 338 513 17 17 3 150; #P user led 303 513 17 17 3 150; #P user led 269 513 17 17 3 150; #P window setfont "Sans Serif" 10.; #P number 233 360 40 10 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 278 360 40 10 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 322 360 40 10 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 366 360 40 10 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 409 360 40 10 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 454 360 40 10 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P toggle 236 170 16 0; #P window setfont "Sans Serif" 9.; #P comment 229 144 40 196617 start; #P window linecount 2; #P comment 379 144 55 196617 serial port settings; #P window setfont Verdana 12.; #P window linecount 1; #P comment 251 387 225 -1006632948 Reading the Arduino's analog pins; #P window setfont "Sans Serif" 9.; #N vpatcher 93 46 1463 876; #P origin 76 34; #N comlet inlet for patcher control; #P inlet 1169 109 15 0; #P window setfont "Sans Serif" 9.; #P message 123 304 69 196617 baud 115200; #P button 330 204 27 0; #P comment 527 95 284 196617 Set the sample rate: between every 15ms and every 100ms.; #P number 330 137 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P user hslider 330 80 38 153 86 1 15 0; #P newex 255 204 48 196617 loadbang; #P newex 188 227 43 196617 delay 4; #P number 1214 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 1149 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 1084 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 1019 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 954 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 889 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 824 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 759 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 694 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 629 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 564 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 499 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 434 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 369 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 304 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 239 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 174 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P number 109 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P window setfont "Sans Serif" 18.; #P comment 570 44 237 196626 Serial Port Settings; #P window setfont "Sans Serif" 9.; #N thispatcher; #Q end; #P newobj 1023 202 61 196617 thispatcher; #P message 1023 181 33 196617 front; #P newex 877 202 47 196617 pcontrol; #P message 877 181 30 196617 open; #N vpatcher 483 171 1200 738; #P origin 0 -1; #P window setfont "Sans Serif" 10.; #P window linecount 0; #P comment 254 165 48 196618 start; #P comment 412 162 56 196618 settings; #P button 339 190 23 5; #P comment 335 163 35 196618 help; #P window linecount 2; #P comment 33 79 493 196618 Arduino2Max uses an Arduino board programmed with the Arduino code that watches the Arduino's input pins and makes the pin data available through receive objects anywere in your patch.; #P window setfont "Sans Serif" 9.; #P window linecount 1; #P comment 549 309 61 196617 digital pins; #P comment 80 309 71 196617 analog pins; #P button 425 190 23 5; #P toggle 253 192 21 0; #N vpatcher -8 44 1287 704; #P origin 67 15; #N comlet inlet to open help patch; #P inlet 666 67 15 0; #N comlet inlet for patcher control; #P inlet 1136 64 15 0; #N comlet 1 or 0 to start/stop serial reads; #P inlet 73 39 15 0; #P pop; #P newobj 253 254 183 196617 p arduinoreader; #P window setfont "Sans Serif" 10.; #P comment 35 417 585 196618 A few notes: - Unused inputs will fluctuate between values. This is normal \, as unconected pins do this on their own.; #P window setfont "Sans Serif" 9.; #P window linecount 3; #P comment 189 343 319 196617 Once you have the above patch \, you can get Arduino's analog and digital values anywere in your own patcher by making a "receive a#" or "receive d#" object \, where # is the input pin you want to read.; #P window linecount 1; #P newex 600 336 29 196617 r d3; #P newex 544 336 29 196617 r d2; #P newex 124 336 29 196617 r a1; #P newex 67 336 29 196617 r a0; #P user led 544 364 17 17 0 150; #P user led 600 364 17 17 3 150; #P window setfont "Sans Serif" 10.; #P number 67 364 40 10 0 0 0 3 0 0 0 255 189 156 222 222 222 0 0 0; #P number 124 364 40 10 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; #P window linecount 2; #P comment 35 462 655 196618 - Arduino2Max runs flawlessly on a 1.83 GHz Macbook Pro \; your mileage may vary.; #P comment 36 491 636 196618 - Patch adapted from Thomas Ouellet Fredericks' "Simple Message Sytem" example. Serial writes are possible \, but not implemented here: see the S.M.S. code.; #P comment 35 433 643 196618 - You may have to change your serial port to suit the port in use. Click on the yellow button to see the guts of the serial read and to make changes to how the patch talks to the serial port.; #P window setfont "Sans Serif" 9.; #P window linecount 7; #P comment 97 175 125 196617 At minimum \, you need the "arduinoreader" patcher at the right \, which does the work of reading the pins. The toggle turns serial reads from the Arduino on and off.; #P comment 495 179 111 196617 The right-hand yellow button opens the patch so that you can adjust settings \, like how often to read from the Arduino and which port to use.; #P window setfont "Sans Serif" 18.; #P window linecount 1; #P comment 33 33 163 196626 Arduino2Max; #B frgb 21 56 9; #P window setfont "Sans Serif" 10.; #P comment 218 39 334 196618 Read the 6 analog and 12 digital input pins of the Arduino into MAX.; #P user panel 18 29 670 101; #X brgb 255 247 207; #X frgb 0 0 0; #X border 0; #X rounded 0; #X shadow 0; #X done; #P hidden inlet 594 21 15 0; #P user panel 18 412 671 114; #X brgb 255 247 207; #X frgb 0 0 0; #X border 0; #X rounded 0; #X shadow 0; #X done; #P user panel 43 332 128 57; #X brgb 130 218 232; #X frgb 0 0 0; #X border 0; #X rounded 0; #X shadow 0; #X done; #P user panel 245 154 227 129; #X brgb 130 218 232; #X frgb 0 0 0; #X border 0; #X rounded 0; #X shadow 0; #X done; #P user panel 515 329 139 57; #X brgb 130 218 232; #X frgb 0 0 0; #X border 0; #X rounded 0; #X shadow 0; #X done; #P connect 17 0 14 0; #P connect 18 0 13 0; #P fasten 24 0 23 0 258 224 258 224; #P connect 30 0 23 1; #P fasten 25 0 23 2 430 226 430 226; #P connect 19 0 16 0; #P connect 20 0 15 0; #P pop; #P newobj 877 224 100 196617 p arduino2max_help; #N comlet inlet to open help patch; #P inlet 877 108 15 0; #P newex 41 97 41 196617 r onoff; #P window linecount 3; #P comment 333 319 292 196617 To change the port in use \, click print above and then enter the letter into the serial object at left that corresponds to the serial port you want to use \, e.g. serial a \, serial b \, and so on.; #N comlet inlet for patcher control; #P inlet 1024 108 15 0; #P window linecount 1; #P comment 877 259 168 196617 help and patcher control stuff.; #N comlet 1 or 0 to start/stop serial reads; #P inlet 109 80 15 0; #P comment 370 211 243 196617 Print a list of serial ports to the max window; #P button 188 259 15 0; #N vpatcher 289 44 1127 677; #P outlet 99 316 15 0; #P window setfont "Sans Serif" 9.; #P window linecount 1; #P newex 107 210 31 196617 spell; #P window linecount 0; #P message 90 241 20 196617 13; #P newex 90 127 27 196617 t b l; #P inlet 90 70 15 0; #P connect 0 0 1 0; #P fasten 1 0 2 0 95 235 95 235; #P fasten 2 0 4 0 95 286 104 286; #P fasten 3 0 4 0 112 286 104 286; #P connect 1 1 3 0; #P pop; #P newobj 109 250 53 196617 p convert; #P newex 1149 657 35 196617 s d12; #B color 14; #P newex 1214 657 35 196617 s d13; #B color 14; #P newex 1084 657 35 196617 s d11; #B color 14; #P newex 1019 657 35 196617 s d10; #B color 14; #P newex 954 657 29 196617 s d9; #B color 14; #P newex 889 657 29 196617 s d8; #B color 14; #P newex 759 657 29 196617 s d6; #B color 14; #P newex 824 657 29 196617 s d7; #B color 14; #P newex 694 657 29 196617 s d5; #B color 14; #P newex 629 657 29 196617 s d4; #B color 14; #P newex 564 657 29 196617 s d3; #B color 14; #P newex 499 657 29 196617 s d2; #B color 14; #P newex 369 657 29 196617 s a4; #B color 14; #P newex 434 657 29 196617 s a5; #B color 14; #P newex 304 657 29 196617 s a3; #B color 14; #P newex 239 657 29 196617 s a2; #B color 14; #P newex 174 657 29 196617 s a1; #B color 14; #P newex 109 657 29 196617 s a0; #B color 14; #N vpatcher 582 197 863 594; #P window setfont "Sans Serif" 9.; #P newex 137 226 64 196617 fromsymbol; #P newex 137 182 40 196617 itoa; #P newex 137 148 61 196617 zl group 78; #P newex 137 84 53 196617 sel 10 13; #N comlet out; #P outlet 137 298 26 0; #N comlet in; #P inlet 137 37 15 0; #P connect 0 0 2 0; #P fasten 2 2 3 0 184 124 142 124; #P fasten 2 1 3 0 163 124 142 124; #P connect 3 0 4 0; #P connect 4 0 5 0; #P connect 5 0 1 0; #P pop; #P newobj 109 372 73 196617 p convertback; #P newex 109 430 52 196617 route list; #P newex 1214 571 49 196617 change 0; #B color 6; #P newex 1149 571 49 196617 change 0; #B color 6; #P newex 1084 571 49 196617 change 0; #B color 6; #P newex 1019 571 49 196617 change 0; #B color 6; #P newex 954 571 49 196617 change 0; #B color 6; #P newex 889 571 49 196617 change 0; #B color 6; #P newex 824 571 49 196617 change 0; #B color 6; #P newex 759 571 49 196617 change 0; #B color 6; #P newex 694 571 49 196617 change 0; #B color 6; #P newex 629 571 49 196617 change 0; #B color 6; #P newex 564 571 49 196617 change 0; #B color 6; #P newex 499 571 49 196617 change 0; #B color 6; #P newex 434 571 49 196617 change 0; #B color 14; #P newex 369 571 49 196617 change 0; #B color 14; #P newex 304 571 49 196617 change 0; #B color 14; #P newex 239 571 49 196617 change 0; #B color 14; #P newex 174 571 49 196617 change 0; #B color 14; #P newex 109 571 49 196617 change 0; #B color 14; #P newex 109 488 1131 196617 unpack i i i i i i i i i i i i i i i i i i; #P message 109 200 14 196617 r; #P toggle 109 117 15 0; #P newex 109 164 52 196617 metro 15; #P newex 109 325 110 196617 serial a 115200 8 1 0; #P message 330 261 32 196617 print; #P user panel 307 36 537 364; #X brgb 206 206 206; #X frgb 0 0 0; #X border 0; #X rounded 0; #X shadow 0; #X done; #P window linecount 0; #P comment 1 305 100 196617 RH: you seem to need to edit the serial object to get the port to work. I'll try and find a solution...; #P connect 49 0 5 0; #P fasten 53 0 5 0 46 115 114 115; #P connect 5 0 4 0; #P connect 4 0 6 0; #P connect 6 0 46 0; #P connect 46 0 3 0; #P fasten 47 0 3 0 193 293 114 293; #P fasten 2 0 3 0 335 301 114 301; #P fasten 85 0 3 0 128 322 114 322; #P connect 3 0 27 0; #P connect 27 0 26 0; #P connect 26 0 7 0; #P connect 7 0 61 0; #P connect 61 0 8 0; #P fasten 8 0 28 0 114 638 114 638; #P fasten 86 0 85 0 1174 296 128 296; #P fasten 82 0 4 1 335 159 156 159; #P connect 7 1 62 0; #P connect 62 0 9 0; #P fasten 9 0 29 0 179 640 179 640; #P fasten 4 0 79 0 114 192 193 192; #P connect 79 0 47 0; #P connect 7 2 63 0; #P connect 63 0 10 0; #P fasten 10 0 30 0 244 640 244 640; #P connect 7 3 64 0; #P connect 64 0 11 0; #P fasten 11 0 31 0 309 640 309 640; #P fasten 81 0 82 0 335 127 335 127; #P connect 84 0 2 0; #P fasten 80 0 2 0 260 241 335 241; #P connect 7 4 65 0; #P connect 65 0 12 0; #P fasten 12 0 33 0 374 640 374 640; #P connect 7 5 66 0; #P connect 66 0 13 0; #P fasten 13 0 32 0 439 640 439 640; #P connect 7 6 67 0; #P connect 67 0 14 0; #P fasten 14 0 34 0 504 640 504 640; #P connect 7 7 68 0; #P connect 68 0 15 0; #P fasten 15 0 35 0 569 640 569 640; #P connect 7 8 69 0; #P connect 69 0 16 0; #P fasten 16 0 36 0 634 640 634 640; #P connect 7 9 70 0; #P connect 70 0 17 0; #P fasten 17 0 37 0 699 640 699 640; #P fasten 7 10 71 0 764 530 764 530; #P fasten 71 0 18 0 764 564 764 564; #P fasten 18 0 39 0 764 640 764 640; #P connect 7 11 72 0; #P connect 72 0 19 0; #P fasten 19 0 38 0 829 640 829 640; #P connect 54 0 56 0; #P hidden connect 56 0 57 0; #P hidden connect 57 0 55 0; #P connect 7 12 73 0; #P connect 73 0 20 0; #P fasten 20 0 40 0 894 640 894 640; #P connect 7 13 74 0; #P connect 74 0 21 0; #P fasten 21 0 41 0 959 640 959 640; #P connect 7 14 75 0; #P connect 75 0 22 0; #P fasten 22 0 42 0 1024 640 1024 640; #P connect 51 0 58 0; #P hidden connect 58 0 59 0; #P connect 7 15 76 0; #P connect 76 0 23 0; #P fasten 23 0 43 0 1089 640 1089 640; #P connect 7 16 77 0; #P connect 77 0 24 0; #P fasten 24 0 45 0 1154 640 1154 640; #P connect 7 17 78 0; #P connect 78 0 25 0; #P fasten 25 0 44 0 1219 640 1219 640; #P pop; #P newobj 236 207 247 196617 p arduinoSerialreader; #P user panel 217 441 484 127; #X brgb 181 181 181; #X frgb 0 0 0; #X border 0; #X rounded 0; #X shadow 0; #X done; #P user panel 216 287 300 128; #X brgb 181 182 182; #X frgb 0 0 0; #X border 0; #X rounded 0; #X shadow 0; #X done; #P user panel 214 131 309 110; #X brgb 181 181 181; #X frgb 0 0 0; #X border 0; #X rounded 0; #X shadow 0; #X done; #P window linecount 3; #P comment 569 365 100 196617 connect sensors to analogue pins to test for thresholds...; #P window linecount 4; #P comment 714 433 100 196617 coonnect a piezo to digital ins (black to ground) to make a series of 'buttons'; #P window setfont "American Typewriter" 14.; #P window linecount 1; #P comment 1022 102 21 199491598 0; #P connect 43 0 16 0; #P fasten 10 0 6 0 241 184 241 184; #P connect 31 0 28 0; #P connect 32 0 17 0; #P connect 44 0 15 0; #P connect 33 0 18 0; #P connect 53 0 6 1; #P connect 45 0 14 0; #P connect 34 0 19 0; #P connect 46 0 13 0; #P fasten 36 0 20 0 379 483 379 483; #P fasten 29 0 6 2 399 185 399 185; #P connect 48 0 12 0; #P connect 35 0 21 0; #P connect 37 0 22 0; #P connect 47 0 11 0; #P connect 73 0 6 3; #P connect 38 0 23 0; #P connect 39 0 24 0; #P fasten 47 0 57 0 459 331 553 331; #P connect 57 0 59 0; #P connect 40 0 25 0; #P connect 42 0 26 0; #P fasten 41 0 27 0 651 487 651 487; #P connect 58 0 57 1; #P fasten 41 0 60 0 651 495 717 495; #P hidden fasten 43 0 67 0 238 610 848 610; #P hidden fasten 44 0 66 0 283 432 848 432; #P hidden fasten 45 0 65 0 327 421 848 421; #P hidden fasten 46 0 64 0 371 271 848 271; #P hidden fasten 48 0 63 0 414 325 848 325; #P hidden fasten 47 0 62 0 459 325 848 325; #P pop;