Pages: [1]   Go Down
Author Topic: Naming shift register pin.  (Read 289 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to name shift register pin 1 to pRow1 and be able to turn it on and off with this name, instead of referring to it by it's pin number each time.

Right now, I can get it to turn on when I write:

setRegisterPin(1, HIGH);

but I want to be able to write

digitalwrite(pRow1, HIGH);

Is what I want to do possible? and if so, how do I make it happen?
Logged

0
Offline Offline
Shannon Member
****
Karma: 220
Posts: 12700
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#define pRow1 1
or
Code:
const int pRow1 = 1 ;
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks!
Code:
const int pRow1 = 1

worked within the loop.
Logged

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

EDIT: Restated

I'd suggest using more descriptive names, and not knowing your application domain, those in my example are rather lame -

Code:
const uint8_t   pinSHIFTREGISTER_ROW_1  = 1;
const uint8_t   SR_ROW_OFF              = LOW;
const uint8_t   SR_ROW_ON               = HIGH;


digitalWrite(pinSHIFTREGISTER_ROW_1, SR_ROW_ON);
« Last Edit: October 30, 2012, 09:55:08 pm by lloyddean » Logged

France
Offline Offline
Edison Member
*
Karma: 38
Posts: 1012
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Another way is to use an enum, for example:
Code:
enum
{
  pRow1 = 1,
  pRow2 = 3,
  pRow3 = 8
};
Logged

Pages: [1]   Go Up
Jump to: