We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpElectronics,  Serial Library › arduino-processing .how to read 10 digital inputs
Page Index Toggle Pages: 1
arduino-processing .how to read 10 digital inputs? (Read 790 times)
arduino-processing .how to read 10 digital inputs?
Apr 6th, 2009, 3:16pm
 
hello, im starting on processing and i've done some Processing's examples like simpleRead....

everything was ok, but now I want to read 10 inputs (pushbuttons) from arduino to processing... here's my first code (Arduino)

Code:
#define DEBUG 1
#define PULLUP 1
#define SWITCH_PRESSED (!PULLUP)
#define NUMBER_OF_PINS 10

byte switchPin[NUMBER_OF_PINS]={3,4,5,6,7,8,9,10,11,12};
boolean switchValues[NUMBER_OF_PINS] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };

void setup (){
 for (byte i=0; i<NUMBER_OF_PINS; i++){
   pinMode (switchPin[i],INPUT);
   if (PULLUP){
digitalWrite(switchPin[i],HIGH);
   }
 }
 if (DEBUG) {Serial.begin (9600);}
}

void loop(){
 for (byte i=0; i<NUMBER_OF_PINS; i++){
   if (digitalRead(switchPin[i])==SWITCH_PRESSED){
switchValues[i]=true;
   }
   else{
switchValues[i]=false;
   }
 }
}

Page Index Toggle Pages: 1