aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2006-08-25 06:18:18 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2006-08-25 06:18:18 +0000
commitfc87836a7801aaab25a25b862a1de5422cc82d64 (patch)
tree3c562f32e7f84fd479f3bc6307a81e213b080025
parent3bfe2c92eab426464fc3e5d7c2d1801d3c32a349 (diff)
got digital inputs working, but needed to make some changes on the order of data coming in, including the analog data
svn path=/trunk/externals/hardware/arduino/; revision=5736
-rw-r--r--Pd_firmware/Pd_firmware.pde50
-rw-r--r--arduino-help.pd120
-rw-r--r--arduino.pd90
3 files changed, 129 insertions, 131 deletions
diff --git a/Pd_firmware/Pd_firmware.pde b/Pd_firmware/Pd_firmware.pde
index ed4b1e0..c17d218 100644
--- a/Pd_firmware/Pd_firmware.pde
+++ b/Pd_firmware/Pd_firmware.pde
@@ -120,21 +120,21 @@
/* Arduino->Computer byte cycle
* ----------------------
- * 0 start of cycle marker (255/11111111)
- * 1 digital read from Arduino // 0-6 bitmask
- * 2 digital read from Arduino // 7-13 bitmask
- * 3 analog input pin 0 from Arduino // byte 0
- * 4 analog input pin 1 from Arduino // byte 1
- * 5 analog input pin 2 from Arduino // byte 2
- * 6 analog input pin 3 from Arduino // byte 3
- * 7 analog input pin 4 from Arduino // byte 4
- * 8 analog input pin 5 from Arduino // byte 5
- * 9 analog input pin 6 from Arduino // byte 6
- * 10 analog input pin 7 from Arduino // byte 10
- * 11 analog input pin 8 from Arduino // byte 11
- * 12 analog input pin 9 from Arduino // byte 12
- * 13 analog input pin 10 from Arduino // byte 13
- * 14 analog input pin 11 from Arduino // byte 14
+ * 0 start of cycle marker (255/11111111)
+ * 1 digital read from Arduino // 0-6 bitmask
+ * 2 digital read from Arduino // 7-13 bitmask
+ * 3 low byte from analog input pin 0
+ * 4 high byte from analog input pin 0
+ * 5 low byte from analog input pin 1
+ * 6 high byte from analog input pin 1
+ * 7 low byte from analog input pin 2
+ * 8 high byte from analog input pin 2
+ * 9 low byte from analog input pin 3
+ * 10 high byte from analog input pin 3
+ * 11 low byte from analog input pin 4
+ * 12 high byte from analog input pin 4
+ * 13 low byte from analog input pin 5
+ * 14 high byte from analog input pin 5
*/
#define TOTAL_DIGITAL_PINS 14
@@ -178,26 +178,24 @@ int analogData;
void transmitDigitalInput(byte startPin) {
byte i;
byte digitalPin;
- byte digitalPinBit;
- byte transmitByte;
+// byte digitalPinBit;
+ byte transmitByte = 0;
byte digitalData;
for(i=0;i<7;++i) {
digitalPin = i+startPin;
- digitalPinBit = OUTPUT << digitalPin;
+/* digitalPinBit = OUTPUT << digitalPin;
// only read the pin if its set to input
if(digitalPinStatus & digitalPinBit) {
digitalData = 0; // pin set to OUTPUT, don't read
}
else if( (digitalPin >= 9) && (pwmStatus & (1 << digitalPin)) ) {
digitalData = 0; // pin set to PWM, don't read
+ }*/
+ if( !(digitalPinStatus & (1 << digitalPin)) ) {
+ digitalData = (byte) digitalRead(digitalPin);
+ transmitByte = transmitByte + ((1 << i) * digitalData);
}
- else {
- digitalData = digitalRead(digitalPin);
- }
- /* the next line probably needs to be re-thought (i.e. it might not work...) since my
- first attempt was miserably wrong. <hans@at.or.at> */
- transmitByte = transmitByte + ((2^i)*digitalData);
}
printByte(transmitByte);
}
@@ -412,7 +410,7 @@ void processInput(byte inputData) {
void setup() {
byte i;
- beginSerial(9600);
+ beginSerial(19200);
for(i=0; i<TOTAL_DIGITAL_PINS; ++i) {
setPinMode(i,INPUT);
}
@@ -442,8 +440,8 @@ void loop() {
analogData = analogRead(analogPin);
// these two bytes get converted back into the whole number in Pd
// the higher bits should be zeroed so that the 8th bit doesn't get set
- printByte(analogData >> 7); // bitshift the big stuff into the output byte
printByte(analogData % 128); // mod by 32 for the small byte
+ printByte(analogData >> 7); // bitshift the big stuff into the output byte
checkForInput();
}
diff --git a/arduino-help.pd b/arduino-help.pd
index a719278..6c78cee 100644
--- a/arduino-help.pd
+++ b/arduino-help.pd
@@ -1,4 +1,4 @@
-#N canvas 157 22 662 554 10;
+#N canvas 325 22 670 562 10;
#X msg 156 146 open \$1;
#N canvas 162 133 534 384 serin 0;
#X obj 120 61 cnv 15 15 15 empty \$0-number-canvas 1 4 8 0 14 -233017
@@ -25,61 +25,64 @@
;
#X msg 216 146 close;
#X obj 63 478 print --------------------;
-#X obj 408 289 tgl 15 0 empty empty changes 0 -6 0 8 -262144 -1 -1
+#X obj 560 290 tgl 15 0 empty empty changes 0 -6 0 8 -262144 -1 -1
0 1;
#X obj 278 29 hradio 15 1 0 14 empty empty empty 0 -6 0 8 -262131 -1
--1 9;
+-1 10;
#X obj 255 30 tgl 15 0 empty empty empty 0 -6 0 8 -262131 -1 -1 0 1
;
-#X obj 355 292 tgl 15 0 empty empty all 0 -6 0 8 -262144 -1 -1 0 1
+#X obj 499 290 tgl 15 0 empty empty all 0 -6 0 8 -262144 -1 -1 0 1
;
-#N canvas 196 579 634 353 decode 0;
+#N canvas 514 440 628 350 decode 0;
#X obj 241 26 inlet;
-#X obj 46 189 & 1;
-#X obj 72 189 & 2;
-#X obj 98 189 & 4;
-#X obj 46 213 tgl 15 0 empty empty 0 4 25 1 12 -262144 -1 -1 0 1;
-#X obj 72 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 2 2
-;
-#X obj 98 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 4
-;
-#X obj 124 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+#X obj 545 189 & 1;
+#X obj 511 189 & 2;
+#X obj 477 189 & 4;
+#X obj 545 213 tgl 15 0 empty empty 0 4 25 1 12 -262144 -1 -1 1 1;
+#X obj 511 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+2;
+#X obj 477 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+4;
+#X obj 433 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 8
8;
-#X obj 150 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 16
+#X obj 389 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
16;
-#X obj 182 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-32;
-#X obj 215 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+#X obj 314 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
64;
-#X obj 248 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 128
+#X obj 277 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
128;
-#X obj 287 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-256;
-#X obj 326 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+#X obj 195 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
512;
-#X obj 365 213 tgl 15 0 empty empty 10 -1 25 1 12 -262144 -1 -1 0 1024
-;
-#X obj 409 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+#X obj 151 213 tgl 15 0 empty empty 10 -1 25 1 12 -262144 -1 -1 1024
+1024;
+#X obj 107 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
2048;
-#X obj 453 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 4096
-4096;
-#X obj 499 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-4;
-#X obj 124 189 & 8;
-#X obj 150 189 & 16;
-#X obj 182 189 & 32;
-#X obj 215 189 & 64;
-#X obj 248 189 & 128;
-#X obj 287 189 & 256;
-#X obj 326 189 & 512;
-#X obj 365 189 & 1024;
-#X obj 409 189 & 2048;
-#X obj 453 189 & 4096;
-#X obj 499 189 & 8192;
+#X obj 63 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 4096
+;
+#X obj 19 213 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 8192
+;
+#X obj 433 189 & 8;
+#X obj 389 189 & 16;
+#X obj 351 189 & 32;
+#X obj 314 189 & 64;
+#X obj 277 189 & 128;
+#X obj 236 189 & 256;
+#X obj 195 189 & 512;
+#X obj 151 189 & 1024;
+#X obj 107 189 & 2048;
+#X obj 63 189 & 4096;
+#X obj 19 189 & 8192;
#X obj 261 273 outlet;
+#X floatatom 296 46 5 0 0 0 - - -;
+#X obj 236 213 tgl 15 0 empty empty 8 -1 25 1 12 -262144 -1 -1 0 256
+;
+#X obj 351 213 tgl 15 0 empty empty 5 -1 25 1 12 -262144 -1 -1 32 32
+;
#X connect 0 0 1 0;
#X connect 0 0 2 0;
#X connect 0 0 3 0;
+#X connect 0 0 16 0;
+#X connect 0 0 17 0;
#X connect 0 0 18 0;
#X connect 0 0 19 0;
#X connect 0 0 20 0;
@@ -89,22 +92,21 @@
#X connect 0 0 24 0;
#X connect 0 0 25 0;
#X connect 0 0 26 0;
-#X connect 0 0 27 0;
#X connect 0 0 28 0;
#X connect 1 0 4 0;
#X connect 2 0 5 0;
#X connect 3 0 6 0;
-#X connect 18 0 7 0;
-#X connect 19 0 8 0;
-#X connect 20 0 9 0;
-#X connect 21 0 10 0;
+#X connect 16 0 7 0;
+#X connect 17 0 8 0;
+#X connect 18 0 30 0;
+#X connect 19 0 9 0;
+#X connect 20 0 10 0;
+#X connect 21 0 29 0;
#X connect 22 0 11 0;
#X connect 23 0 12 0;
#X connect 24 0 13 0;
#X connect 25 0 14 0;
#X connect 26 0 15 0;
-#X connect 27 0 16 0;
-#X connect 28 0 17 0;
#X restore 473 488 pd decode buttons;
#X obj 57 23 hsl 128 15 0 1 0 0 empty empty PWM_control_(0-1) -2 -6
1 10 -225271 -1 -1 0 0;
@@ -117,8 +119,8 @@
#X msg 165 44 PWM2;
#X msg 129 44 PWM1;
#X msg 94 44 PWM0;
-#X obj 67 215 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 16383
-16383;
+#X obj 67 215 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 16383
+;
#X obj 67 178 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1
;
#X obj 21 336 spigot 0;
@@ -126,20 +128,20 @@
;
#X obj 21 358 route analog0 analog1 analog2 analog3 analog4 analog5
;
-#X obj 414 408 route digital;
-#X obj 487 428 print GARBAGE;
+#X obj 435 403 route digital;
+#X obj 521 423 print GARBAGE;
#X floatatom 430 488 6 0 0 0 - - -;
#X text 393 56 how many analogIns to enable:;
-#X obj 405 117 tgl 15 1 empty empty empty 0 -6 0 8 -257472 -1 -1 1
+#X obj 405 117 tgl 15 1 empty empty empty 0 -6 0 8 -257472 -1 -1 0
1;
#X text 428 116 enable/disable digitalIns;
#X msg 405 135 digitalIns \$1;
#X msg 394 90 analogIns \$1;
#N canvas 162 133 546 396 serin 0;
-#X obj 165 61 cnv 15 15 15 empty \$0-analog-number-canvas 6 4 8 0 14
+#X obj 165 61 cnv 15 15 15 empty \$0-analog-number-canvas 0 4 8 0 14
-233017 -1 0;
#X obj 60 61 hradio 15 1 1 7 empty empty empty 0 -6 0 8 -225280 -1
--1 6;
+-1 0;
#X obj 59 147 outlet;
#X obj 60 13 inlet;
#X msg 200 202 label \$1;
@@ -161,7 +163,7 @@
1;
#X obj 367 483 print;
#X text 5 229 this will flash any pin set to output;
-#N canvas 0 22 261 248 speed 0;
+#N canvas 0 22 269 256 speed 0;
#X obj 21 41 inlet;
#X obj 21 62 maxlib/speedlim 100;
#X obj 21 84 outlet;
@@ -199,7 +201,7 @@
#X connect 19 0 20 0;
#X restore 21 380 pd speed limiting for displaying values with pegging
the CPU;
-#N canvas 77 268 454 304 debugging 0;
+#N canvas 77 268 458 308 debugging 0;
#X obj 136 31 inlet;
#X obj 324 29 inlet;
#X obj 27 31 inlet;
@@ -227,8 +229,8 @@ the CPU;
#X connect 10 0 12 0;
#X connect 11 0 8 0;
#X connect 12 0 11 0;
-#X restore 304 311 pd debugging stuff;
-#X text 334 209 use raw data to save settings more compactly;
+#X restore 439 308 pd debugging stuff;
+#X text 315 193 use raw data to save settings more compactly;
#X floatatom 21 405 5 0 0 0 - - -;
#X floatatom 80 405 5 0 0 0 - - -;
#X floatatom 139 405 5 0 0 0 - - -;
@@ -305,7 +307,7 @@ bits of digital output values per byte.;
#X connect 22 0 16 0;
#X restore 10 258 pd sending digital outs;
#X obj 255 274 arduino 3;
-#X msg 381 225 251 \, 9 \, 20 \, 142 \, 213;
+#X msg 362 209 251 \, 9 \, 20 \, 142 \, 213;
#X connect 0 0 61 0;
#X connect 1 0 0 0;
#X connect 5 0 61 0;
diff --git a/arduino.pd b/arduino.pd
index 53ac978..4bc1c29 100644
--- a/arduino.pd
+++ b/arduino.pd
@@ -1,9 +1,9 @@
-#N canvas 158 31 627 495 10;
+#N canvas 289 52 628 497 10;
#X obj 504 -5 import flatspace;
#X text 414 457 released under the GNU GPL;
#X text 9 457 (C) Copyright 2006 Hans-Christoph Steiner <hans@at.or.at>
;
-#N canvas 562 456 466 316 alternate 0;
+#N canvas 562 456 470 320 alternate 0;
#X obj 87 8 inlet;
#X obj 151 244 outlet;
#X obj 319 247 outlet;
@@ -11,7 +11,6 @@
#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;
@@ -23,31 +22,30 @@
#X obj 86 54 bang;
#X msg 73 82 1;
#X msg 103 82 0;
-#X connect 0 0 12 0;
+#X connect 0 0 11 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 13 0;
-#X connect 9 0 14 0;
-#X connect 10 0 3 1;
-#X connect 10 0 7 0;
-#X connect 10 0 14 1;
-#X connect 11 0 4 1;
-#X connect 11 0 13 1;
-#X connect 12 0 16 0;
-#X connect 12 1 5 0;
-#X connect 13 0 8 0;
-#X connect 14 0 6 0;
-#X connect 15 0 18 0;
+#X connect 5 1 8 0;
+#X connect 6 0 9 0;
+#X connect 7 0 10 0;
+#X connect 8 0 12 0;
+#X connect 8 0 13 0;
+#X connect 9 0 3 1;
+#X connect 9 0 13 1;
+#X connect 10 0 4 1;
+#X connect 10 0 12 1;
+#X connect 11 0 15 0;
+#X connect 11 1 5 0;
+#X connect 12 0 7 0;
+#X connect 13 0 6 0;
+#X connect 14 0 17 0;
+#X connect 14 0 16 0;
#X connect 15 0 17 0;
-#X connect 16 0 18 0;
-#X connect 16 0 17 0;
-#X connect 17 0 14 1;
-#X connect 18 0 13 1;
+#X connect 15 0 16 0;
+#X connect 16 0 13 1;
+#X connect 17 0 12 1;
#X restore 66 161 pd alternate;
#X msg 11 130 reset;
#X obj 120 203 +;
@@ -55,11 +53,10 @@
#X obj 126 375 pack symbol float;
#X msg 124 258 0;
#X obj 11 108 select 255;
-#X obj 133 182 * 128;
+#X obj 66 180 * 128;
#X obj 11 -9 inlet;
#X obj 126 425 outlet;
#X obj 494 241 outlet;
-#X obj 11 66 comport \$1 9600;
#N canvas 240 171 586 331 command 0;
#X obj 79 8 inlet;
#X obj 198 269 outlet;
@@ -152,30 +149,31 @@
#X obj 443 -5 inlet;
#X text 382 -10 raw input;
#X text 48 -11 processed input;
-#X connect 3 0 5 0;
-#X connect 3 1 10 0;
+#X obj 11 66 comport \$1 19200;
+#X connect 3 0 10 0;
+#X connect 3 1 5 1;
#X connect 4 0 3 0;
#X connect 4 0 8 0;
#X connect 5 0 6 0;
-#X connect 6 0 19 0;
+#X connect 6 0 18 0;
#X connect 6 1 7 1;
-#X connect 7 0 21 0;
-#X connect 8 0 19 1;
+#X connect 7 0 20 0;
+#X connect 8 0 18 1;
#X connect 9 0 4 0;
-#X connect 9 1 16 0;
-#X connect 10 0 5 1;
-#X connect 11 0 15 0;
-#X connect 14 0 9 0;
-#X connect 14 0 13 0;
-#X connect 15 0 14 0;
-#X connect 16 0 3 0;
+#X connect 9 1 15 0;
+#X connect 10 0 5 0;
+#X connect 11 0 14 0;
+#X connect 14 0 27 0;
+#X connect 15 0 3 0;
+#X connect 16 0 7 0;
#X connect 17 0 7 0;
-#X connect 18 0 7 0;
-#X connect 19 0 20 0;
-#X connect 19 0 22 0;
-#X connect 20 0 19 1;
-#X connect 21 0 12 0;
-#X connect 22 0 17 0;
-#X connect 22 1 24 0;
-#X connect 24 0 18 0;
-#X connect 25 0 14 0;
+#X connect 18 0 19 0;
+#X connect 18 0 21 0;
+#X connect 19 0 18 1;
+#X connect 20 0 12 0;
+#X connect 21 0 16 0;
+#X connect 21 1 23 0;
+#X connect 23 0 17 0;
+#X connect 24 0 27 0;
+#X connect 27 0 9 0;
+#X connect 27 0 13 0;