Pages: [1]   Go Down
Author Topic: Setting pinMode with less typing  (Read 342 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 111
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
       
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);
    }
}

Logged

Pages: [1]   Go Up
Jump to: