Pages: [1]   Go Down
Author Topic: declare 1 pin on 2 names  (Read 547 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 250
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

HI. i would like to know if i can declare 2 integer on 1 pin
example

  int CY62148EV30_A0=35;
  int DS1744W_A0=35;

  pinMode(CY62148EV30_A0,OUTPUT); 
  pinMode(DS1744W_A0,OUTPUT);

if i do that can i use (digitalread,digitalWrite) any of them without problem?
Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 78
Posts: 1719
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yea, thats fine.

You aren't declaring a 'pin' per say. You just have two variables which contain a number. It just so happens (by intent) that said number matches the number arduino calls one of its pins.

All the defining of pins is done somewhere else, you aren't actually redefining them.

Just FYI, you can same memory by declaring the pin numbers as 'byte' not 'int' as it makes no difference (short answer) to the code, but it uses half as much memory. Also if the pin never changes which is usually the case, you can use 'const byte' which takes up no memory, as the compiler optimises it out to a constant value.
« Last Edit: July 11, 2012, 01:39:26 pm by TCWORLD » Logged

~Tom~

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can, but why do you want to? It looks like it would have great potential to cause very confusing bugs.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 250
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

actually i created my own PCB board with PIC32MX795F512 with many components (FRAM,RAM,EEPROM) and i have common pins on some components (CY62148EV30,DS1744W)
i am using arduino code so i prefer to not have common names (variables) on both components. It will be easier to program them
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 219
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well essentially
you set a variable name to 35 and you use it to refer to the 35th pin (arduino mega i guess it has lots of pins)
Variables can have the same name, i'd prefer logical small names, but you can call variables how you want compilers dont use these name in the final compiled code.

what you do next is saying that a certain pin number,   the pin number 35 as described by this variable ,  will be set to OUTPUT mode.

It is not forbidden to do so, in most programs its not practical.
There you just make a setup in which you define how the pins or ports (whatever you call them) should react.
But you can create program that sets pins on specific connected devices.

In such case you might as well use arrays, and use a while loop to set each pin for specific connected devices.
For example
array int Board1 [34,35,12,11,10'] // use a loop to set each port number 
array int board1 [  1,  1,  1, 0, 1]  // if value is 1 set it as output, 0 for input, ...

i use this sometimes to set many specific pins for output.


Note you have to make something for selecting your board because if one board uses a pin for input and another for output.. then you cannt call them just right after eachother, then the last call on how you want to set the board will be the one that is active.

maybe use a serial connection read, (connected to a computer) listen for a board name, and then set the pins like that
once you have them set you wont do this again '(simply dont send it again)
depending on name create a
If (boardname =="yourboard"){ //do this routine for setting up pins};
boardname = "" ; //clear variable so line above wont run again.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12568
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

HI. i would like to know if i can declare 2 integer on 1 pin
example

  int CY62148EV30_A0=35;
  int DS1744W_A0=35;

  pinMode(CY62148EV30_A0,OUTPUT); 
  pinMode(DS1744W_A0,OUTPUT);

if i do that can i use (digitalread,digitalWrite) any of them without problem?

You can declare both values to be 35, no problem. But if you're passing these to an Arduino function that expects to receive a pin number, such as pinMode(), then both values reference the SAME pin. From your later posts, I don't think the two values do actually represent input/output pin numbers as your example above implies so perhaps this isn't an issue. But taking the code above at face value, you are using two names to refer to the same pin and this is almost certainly not what you're trying to achieve.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: