diff options
-rw-r--r-- | examples/PD_all_inputs.pd | 233 | ||||
-rw-r--r-- | examples/Pd_Input/Pd_Input.pde | 57 |
2 files changed, 192 insertions, 98 deletions
diff --git a/examples/PD_all_inputs.pd b/examples/PD_all_inputs.pd index 8f78216..90b756d 100644 --- a/examples/PD_all_inputs.pd +++ b/examples/PD_all_inputs.pd @@ -1,95 +1,158 @@ -#N canvas 159 48 492 617 10; -#X obj 346 18 import zexy; -#X text 112 148 On Mac OS X \, set this to the right value:; -#X text 5 38 You might need to select another port \, check the Pd +#N canvas 970 165 635 705 10; +#X obj 480 668 import zexy; +#X obj 21 78 nbx 4 16 -1e+37 1e+37 0 0 empty empty empty 0 -6 0 14 +-241291 -1 -1 0 256; +#X obj 91 78 nbx 3 16 -1e+37 1e+37 0 0 empty empty empty 0 -6 0 14 +-241291 -1 -1 0 256; +#X obj 161 78 nbx 3 16 -1e+37 1e+37 0 0 empty empty empty 0 -6 0 14 +-241291 -1 -1 0 256; +#X obj 231 78 nbx 3 16 -1e+37 1e+37 0 0 empty empty empty 0 -6 0 14 +-241291 -1 -1 0 256; +#X obj 301 78 nbx 3 16 -1e+37 1e+37 0 0 empty empty empty 0 -6 0 14 +-241291 -1 -1 0 256; +#X obj 371 78 nbx 3 16 -1e+37 1e+37 0 0 empty empty empty 0 -6 0 14 +-241291 -1 -1 0 256; +#X obj 21 132 nbx 6 16 -1e+37 1e+37 0 0 empty empty empty 0 -6 0 14 +-3754 -1 -1 0 256; +#X obj 122 132 nbx 6 16 -1e+37 1e+37 0 0 empty empty empty 0 -6 0 14 +-3754 -1 -1 0 256; +#X obj 223 132 nbx 6 16 -1e+37 1e+37 0 0 empty empty empty 0 -6 0 14 +-3754 -1 -1 0 256; +#X text 160 241 On Mac OS X \, set this to the right value:; +#X msg 100 220 open \$1; +#X obj 100 287 comport 1 9600; +#X text 15 156 You might need to select another port \, check the Pd window to see if it connected successfully:; -#X msg 136 120 close; -#X msg 116 165 devicename /dev/tty.usbserial-191; -#X obj 11 508 nbx 4 20 -1e+37 1e+37 0 0 empty empty ADC0 5 30 1 10 --3754 -1 -1 508 256; -#N canvas 162 133 518 368 serin 0; -#X obj 160 101 cnv 15 15 15 empty \$0-number-canvas 1 4 7 0 14 -233017 +#X obj 724 492; +#X msg 823 352; +#X obj 838 350; +#X msg 820 369; +#X text 16 5 This patch works with the example Arduino firmware of +the same name.; +#N canvas 162 133 526 376 serin 0; +#X obj 120 61 cnv 15 15 15 empty \$0-number-canvas 1 4 7 0 14 -233017 -1 0; -#X obj 241 251 s \$0-number-canvas; -#X obj 100 101 hradio 15 1 0 4 empty empty empty 0 -6 0 8 -225271 -1 +#X obj 200 225 s \$0-number-canvas; +#X obj 60 61 hradio 15 1 0 4 empty empty empty 0 -6 0 8 -225271 -1 -1 0; -#X obj 101 134 + 1; -#X obj 100 173 outlet; -#X obj 101 39 inlet; -#X msg 241 228 label \$1; -#X obj 241 206 makefilename %d; +#X obj 60 108 + 1; +#X obj 59 147 outlet; +#X obj 60 13 inlet; +#X msg 200 202 label \$1; +#X obj 200 180 makefilename %d; #X connect 2 0 3 0; #X connect 3 0 4 0; #X connect 3 0 7 0; #X connect 5 0 2 0; #X connect 6 0 1 0; #X connect 7 0 6 0; -#X coords 0 -1 1 1 76 17 1 100 100; -#X restore 77 71 pd serin; -#X msg 77 119 open \$1; -#X text 4 -3 This patch works with the example Arduino firmware of -the same name.; -#X text 9 552 CAUTION! Watch out if you connect your potentiometer -without an extra resistor \, when you turn it all the way up \, the -full voltage and current will go to the input. This could fry your -board!; -#X obj 79 357 +; -#X obj 78 259 trigger float bang; -#X obj 95 318 float; -#X obj 95 337 * 10; -#X obj 176 345 float; -#X msg 196 290 0; -#X text 250 459 ASCII for A B C D E F; -#X obj 77 235 - 48; -#X obj 79 460 route 65 66 67 68 69 70; -#X obj 79 378 trigger bang float; -#X obj 79 417 float; -#X obj 247 386 float; -#X obj 79 440 pack float float; -#X obj 61 508 nbx 4 20 -1e+37 1e+37 0 0 empty empty ADC1 5 30 1 10 +#X coords 0 -1 1 1 76 17 1 60 60; +#X restore 100 197 pd serin; +#X text 181 198 serial port #; +#X obj 21 112 receive A; +#X obj 122 112 receive B; +#X obj 223 112 receive C; +#X obj 91 58 receive E; +#X obj 21 58 receive D; +#X obj 161 58 receive F; +#X obj 231 58 receive G; +#X obj 301 58 receive H; +#X obj 371 58 receive I; +#X text 12 95 potentiometers:; +#X text 10 39 pushbuttons; +#X text 281 675 released under the GNU GPL; +#X text 67 660 (C) Copyright 2006 Hans-Christoph Steiner <hans@at.or.at> +; +#X obj 324 132 nbx 6 16 -1e+37 1e+37 0 0 empty empty empty 0 -6 0 14 +-3754 -1 -1 0 256; +#X obj 425 132 nbx 6 16 -1e+37 1e+37 0 0 empty empty empty 0 -6 0 14 +-3754 -1 -1 0 256; +#X obj 526 132 nbx 6 16 -1e+37 1e+37 0 0 empty empty empty 0 -6 0 14 -3754 -1 -1 0 256; -#X obj 111 508 nbx 4 20 -1e+37 1e+37 0 0 empty empty ADC2 5 30 1 10 --3754 -1 -1 10 256; -#X obj 161 508 nbx 4 20 -1e+37 1e+37 0 0 empty empty ADC3 5 30 1 10 --3754 -1 -1 98 256; -#X obj 211 508 nbx 4 20 -1e+37 1e+37 0 0 empty empty ADC4 5 30 1 10 --3754 -1 -1 158 256; -#X obj 261 508 nbx 4 20 -1e+37 1e+37 0 0 empty empty ADC5 5 30 1 10 --3754 -1 -1 623 256; -#X obj 320 511 print ERRANT_VALUE; -#X obj 247 250 float; -#X obj 77 211 moses 58; -#X text 84 88 (sometimes it takes up to 10 seconds to close the serial -port \, if things are running fast); -#X text 181 121 <-- close before uploading a new firmware!; -#X obj 77 188 comport 1 19200; -#X connect 3 0 33 0; -#X connect 4 0 33 0; -#X connect 6 0 7 0; -#X connect 7 0 33 0; -#X connect 10 0 14 0; -#X connect 10 0 19 0; -#X connect 11 0 10 0; -#X connect 11 1 12 0; -#X connect 12 0 13 0; -#X connect 13 0 10 1; -#X connect 14 0 12 1; -#X connect 15 0 12 1; -#X connect 17 0 11 0; -#X connect 18 0 5 0; -#X connect 18 1 23 0; -#X connect 18 2 24 0; -#X connect 18 3 25 0; -#X connect 18 4 26 0; -#X connect 18 5 27 0; -#X connect 18 6 28 0; -#X connect 19 0 20 0; -#X connect 19 1 22 1; -#X connect 20 0 22 0; -#X connect 21 0 20 1; -#X connect 22 0 18 0; -#X connect 29 0 15 0; -#X connect 29 0 21 0; -#X connect 30 0 17 0; -#X connect 30 1 29 0; -#X connect 33 0 30 0; +#X obj 324 112 receive D; +#X obj 425 112 receive E; +#X obj 526 112 receive F; +#X obj 65 383 spigot; +#X obj 105 361 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 +1; +#X msg 160 220 close; +#X obj 68 492 print --------------------; +#X obj 67 434 select 10 65; +#X obj 105 466 print A; +#X obj 163 454 print; +#X msg 164 259 devicename /dev/tty.usbserial-0B1; +#N canvas 630 635 454 304 alternate 0; +#X obj 87 8 inlet; +#X obj 151 244 outlet; +#X obj 319 247 outlet; +#X obj 159 197 spigot; +#X obj 319 191 spigot; +#X obj 158 57 trigger anything bang; +#X obj 196 152 abs; +#X floatatom 212 198 5 0 0 0 - - -; +#X obj 356 147 abs; +#X msg 295 77 1; +#X obj 196 173 float; +#X obj 355 168 float; +#X obj 86 34 route reset; +#X msg 103 82 1; +#X obj 356 128 -; +#X msg 73 82 0; +#X obj 196 133 -; +#X obj 15 35 loadbang; +#X obj 86 54 bang; +#X connect 0 0 12 0; +#X connect 3 0 1 0; +#X connect 4 0 2 0; +#X connect 5 0 3 0; +#X connect 5 0 4 0; +#X connect 5 1 9 0; +#X connect 6 0 10 0; +#X connect 8 0 11 0; +#X connect 9 0 14 0; +#X connect 9 0 16 0; +#X connect 10 0 3 1; +#X connect 10 0 7 0; +#X connect 10 0 16 1; +#X connect 11 0 4 1; +#X connect 11 0 14 1; +#X connect 12 0 18 0; +#X connect 12 1 5 0; +#X connect 13 0 14 1; +#X connect 14 0 8 0; +#X connect 15 0 16 1; +#X connect 16 0 6 0; +#X connect 17 0 13 0; +#X connect 17 0 15 0; +#X connect 18 0 13 0; +#X connect 18 0 15 0; +#X restore 286 465 pd alternate; +#X msg 317 423 reset; +#X obj 285 499 print HIGH; +#X obj 365 498 print LOW; +#X connect 11 0 12 0; +#X connect 12 0 40 0; +#X connect 19 0 11 0; +#X connect 21 0 7 0; +#X connect 22 0 8 0; +#X connect 23 0 9 0; +#X connect 24 0 2 0; +#X connect 25 0 1 0; +#X connect 26 0 3 0; +#X connect 27 0 4 0; +#X connect 28 0 5 0; +#X connect 29 0 6 0; +#X connect 37 0 34 0; +#X connect 38 0 35 0; +#X connect 39 0 36 0; +#X connect 40 0 44 0; +#X connect 41 0 40 1; +#X connect 42 0 12 0; +#X connect 44 0 43 0; +#X connect 44 1 45 0; +#X connect 44 2 46 0; +#X connect 44 2 48 0; +#X connect 47 0 12 0; +#X connect 48 0 50 0; +#X connect 48 1 51 0; +#X connect 49 0 48 0; diff --git a/examples/Pd_Input/Pd_Input.pde b/examples/Pd_Input/Pd_Input.pde index d5dd5e7..2099ffb 100644 --- a/examples/Pd_Input/Pd_Input.pde +++ b/examples/Pd_Input/Pd_Input.pde @@ -1,15 +1,18 @@ /* Pd_Input * ------------------ * - * This program reads all of the Analog inputs - * and sends the data to the computer as fast as - * possible. It was designed to work with the Pd - * patch of the same name in: - * Help -> Browser -> examples -> hardware + * This program reads all of the Analog and 12 Digital Inputs + * and sends the data to the computer as fast as possible. + * It reads one analog pin and two digital pins per cycle + * so that the time between reads on all pins remains + * constant. + * + * It was designed to work with the Pd patch of the same + * name in: Help -> Browser -> examples -> hardware * * (cleft) 2006 Hans-Christoph Steiner * @author: Hans-Christoph Steiner - * @date: 2006-03-04 + * @date: 2006-03-10 * @location: Polytechnic University, Brooklyn, New York, USA */ @@ -19,15 +22,43 @@ * without a delay() so its very fast. */ -int potPin = 0; +int analogPin = 0; +int digitalPin = 0; +int ledOut = 1; +int analogIn = 0; void setup() { - beginSerial(19200); + beginSerial(9600); } void loop() { - printByte(potPin + 65); // add 65 to get ASCII chars starting with A - printInteger(analogRead(potPin)); - potPin = potPin + 1; - if (potPin > 5) - potPin = 0; + /* + * get two digital ins + */ +/* + printByte(digitalRead(digitalPin)); + digitalPin = digitalPin + 1; + if (digitalPin > 11) + digitalPin = 0; + printByte(digitalRead(digitalPin)); + digitalPin = digitalPin + 1; + if (digitalPin > 11) + digitalPin = 0; +*/ + /* + * get analog in + */ + printByte(65); + analogIn = analogRead(analogPin); + printByte(analogIn / 127); + printByte(analogIn % 127); + analogPin = analogPin + 1; + if (analogPin > 5) + { + analogPin = 0; + // toggle the status LED (pin 13) + digitalWrite(13,ledOut); + ledOut = !ledOut; // alternate the LED + // the newline (ASCII 10) marks the start/end of the sequence + printNewline(); + } } |