aboutsummaryrefslogtreecommitdiff
path: root/examples/Pd_Input
diff options
context:
space:
mode:
Diffstat (limited to 'examples/Pd_Input')
-rw-r--r--examples/Pd_Input/Pd_Input.pde41
1 files changed, 24 insertions, 17 deletions
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);
}
}