Go Down

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


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

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131