From 36f0cb2366c18e2bde1d94c70ed7fb03dcb21e83 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 14 Mar 2006 22:31:39 +0000 Subject: got the basics of the byte-based speedy firmware working, now I got to get the Pd patch working with this firmware svn path=/trunk/externals/hardware/arduino/; revision=4708 --- examples/Pd_Input/Pd_Input.pde | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'examples/Pd_Input/Pd_Input.pde') diff --git a/examples/Pd_Input/Pd_Input.pde b/examples/Pd_Input/Pd_Input.pde index 2099ffb..c2d574f 100644 --- a/examples/Pd_Input/Pd_Input.pde +++ b/examples/Pd_Input/Pd_Input.pde @@ -22,10 +22,13 @@ * without a delay() so its very fast. */ +int i; int analogPin = 0; int digitalPin = 0; int ledOut = 1; -int analogIn = 0; +int analogData = 0; +int digitalData = 0; +int digitalOutputByte = 0; void setup() { beginSerial(9600); } @@ -33,24 +36,28 @@ void setup() { void loop() { /* * 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; -*/ + */ + digitalOutputByte = 0; + for(i=0;i<7;++i) + { + digitalData = digitalRead(i); + digitalOutputByte = digitalOutputByte + (2^(i+1)*digitalData); + } + printByte(digitalOutputByte); + digitalOutputByte = 0; + for(i=7;i<13;++i) + { + digitalData = digitalRead(i); + digitalOutputByte = digitalOutputByte + (2^(i-6)*digitalData); + } + printByte(digitalOutputByte); /* * get analog in */ - printByte(65); - analogIn = analogRead(analogPin); - printByte(analogIn / 127); - printByte(analogIn % 127); + analogData = analogRead(analogPin); + // these two bytes get converted back into the whole number in Pd + printByte(analogData / 32); // div by 32 for the big byte + printByte(analogData % 32); // mod by 32 for the small byte analogPin = analogPin + 1; if (analogPin > 5) { @@ -59,6 +66,6 @@ void loop() { digitalWrite(13,ledOut); ledOut = !ledOut; // alternate the LED // the newline (ASCII 10) marks the start/end of the sequence - printNewline(); + printByte(255); } } -- cgit v1.2.1