Go Down

Topic: Setting pinMode with less typing (Read 347 times) previous topic - next topic

nomuse

This is old-hat to the experienced coders, and probably not efficient coding anyhow, but I find it more elegant for setting a bunch of input/output pins at once (also means I can see what pins I'm using with a single glance at the top of the sketch);



Code: [Select]

       
int inp[4] = {2, 3, 4, 5};
int oup[4] = {8, 9, 10, 11};
int count = 0;

void setup()                  
{    
 for (count = 0; count <=3; count ++)
   {
   pinMode(inp[count], INPUT);
   digitalWrite(inp[count], HIGH);   // turning on internal pullup resistors
   pinMode(oup[count], OUTPUT);
//    digitalWrite(oup[count], HIGH);  // flash all output LEDs once
//    delay(200);                              // to confirm they work
   digitalWrite(oup[count], LOW);
   }
}


Go Up