Give PIN a name, define

is it possible to giving pins a name, alias?
//Arrays input/output pins:
int outPin[] = {22,24,26,28,30,32,34,36};
int inPin[] = {5,6,7,8,9,10,11,12};

define?

Thanks

Not sure what you want.

#define tom    10
#define dick   11
#define harry  12

byte outPin[] = {tom, dick, harry};


1 Like

LCD display still sees 5,6,22,23

#define A 5
#define B 6
#define C 22
#define D 23
byte outPin[] = {C, D};
byte inPin[] = {A, B};

LCD ?

You obviously know exactly what this is all about.

We don’t.

Please explain a lot more than you have.

I am running pin loop on display, I prefer not to see loop pin# 5,6,22,23
I want to give it a name than pin# or the loop start out #1 instead 22 (#2 = 23)

Show your code.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

//Arrays to set which pins are outputs and which are inputs:
#define A  1
#define B  2
#define C  3
#define D  4
byte outPin[] = {C, D};
byte inPin[]  = {A, B};
int pin_size = 2;
int loop_count = 0;
int voltage;

void setup() {
  lcd.init();
  lcd.backlight();

  //initialize the digital pin as an output or input:
  pinMode((byte)outPin, OUTPUT);
  pinMode((byte)inPin, INPUT);

  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 0);
  lcd.print("checking pin...");
  delay(1000);
  lcd.clear();

}

void loop() {

  // Send the outputs.
  digitalWrite(outPin[loop_count], HIGH);
  delay(100);
  digitalWrite(outPin[loop_count], LOW);
  delay(100);

  // Receive the inputs:
  voltage = digitalRead(inPin[loop_count]);

  lcd.print ("WIRE " + String(inPin[loop_count]) + ": ");

  // LCD prints PASS or FAIL status using a switch statement:
  switch (voltage) {

    case HIGH:
      lcd.print("PASS");
      break;

    case LOW:
      lcd.print("FAIL");
      break;

    default:
      lcd.print("SHORT?");
  }

  // Delay and increment the loop counter for the next set of pins.
  delay(1000);
  loop_count++;
  lcd.clear();

  // Check if reached the end of all pins.
  if (loop_count == pin_size) {
    lcd.print ("Test Completed");
    delay(2000);
    lcd.clear();
    lcd.print("Testing again...");
    delay(1000);
    lcd.clear();
    loop_count = 0;
  }
}
byte outPin[] = {C, D};

. . .


for(byte x = 0; x < 2; x++)
{
    pinMode(output(x), OUTPUT);
}

It is not straight forward; you can use a lookup table in some form (below used a struct that associates a pin number with a name). Code provided to demonstrate. Enter a number in serial monitor and it will show you the name (if found).

struct LOOKUP
{
  const uint8_t pinNo;
  const char *text;
};

LOOKUP inputPinNames[] =
{
  {5, "A"},
  {6, "B"},
};

LOOKUP outputPinNames[] =
{
  {22, "C"},
  {23, "D"},
};

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  if (Serial.available())
  {
    int x = Serial.parseInt();

    for (uint8_t cnt = 0; cnt < sizeof(inputPinNames) / sizeof(inputPinNames[0]); cnt++)
    {
      if (inputPinNames[cnt].pinNo == x)
      {
        Serial.println(inputPinNames[cnt].text);
      }
    }

    for (uint8_t cnt = 0; cnt < sizeof(outputPinNames) / sizeof(outputPinNames[0]); cnt++)
    {
      if (outputPinNames[cnt].pinNo == x)
      {
        Serial.println(outputPinNames[cnt].text);
      }
    }
  }
}

'output' was not declared in this scope

#define C 22
#define D 23
byte outPin[] = {C, D};
int inPin[] = {5, 6};
int pin_size = 2;
int loop_count = 0;
int voltage;

void setup() {
    lcd.init(); 
    lcd.backlight(); 

//initialize the digital pin as an output or input:

pinMode((int)inPin, INPUT);

for(byte x = 0; x < 2; x++)
{
    pinMode(output(x), OUTPUT);
}

won't run your code, nothing show up in serial monitor

Sorry, spelling mistake.

byte outPin[] = {C, D};

. . .


for(byte x = 0; x < 2; x++)
{
    pinMode(outPin(x), OUTPUT);
}

Set baudrate correctly to 115200.
Set line ending to newline.

That's my default. btw, I need that display on LCD though.

something still not right:
'outPin' cannot be used as a function

#define C 22
#define D 23
byte outPin[] = {C, D};
int inPin[] = {5, 6};
int pin_size = 2;
int loop_count = 0;
int voltage;

void setup() {
    lcd.init(); 
    lcd.backlight(); 

    //initialize the digital pin as an output or input:
    pinMode((int)inPin, INPUT);
    
byte outPin[] = {C, D};
for(byte x = 0; x < 2; x++)
{
    pinMode(outPin(x), OUTPUT);
}

DAMN it is way too late, too many mistakes going to sleep :sleeping:

This should should be:

byte outPin[] = {C, D};

. . .


for(byte x = 0; x < 2; x++)
{
    pinMode(outPin[x], OUTPUT);
}

able to upload sketch but pin still showing 5,6 not C, D.
go sleep Larry, thanks for your help.
gnite :slight_smile:

It's abig difference if you want to give your pins a name to be used in your sketch ( as Larry did ), or if you want to give the pins a name that can be printed in the sketch ( no matter on LCD or serial monitor ).
Usage of the pin names in the sketch should be always done. It is not advised to use magic numbers in the sketch.
Pin names to be printed in the sketch is rarely used. @sterretje showed how this can be done.

Understood, thanks everyone for helping me. At least i know now. Am still wondering how this guy can do this.
Capture

// Create a Data Structure for each USB type
// Sensor Number , Pin Number, Status, Text description of pin and function

struct usbCleft {
  byte pinnumber;       // 62 to 69, 14 to 29 sensor pin addresses
  char* function;       // Text description of function and logical pin number
  byte refnum;           // Position of pin in rightside or leftside array
}

usbCleft[24] = {

{ 46,"A1   GND",0},
{ 48,"A2  TX1+",1},
{ 50,"A3  TX1-",2},
{ 52,"A4  vBUS",3},
{ 14,"A5   CC1",4},
{ 15,"A6    D+",5},
{ 16,"A7    D-",6},
{ 17,"A8  SBU1",7},
{ 18,"A9  vBUS",8},
{ 19,"A10 RX2-",9},
{ 20,"A11 RX2+",10},
{ 21,"A12  GND",11},
{ 22,"B1   GND",12},
{ 24,"B2  TX2+",13},
{ 26,"B3  TX2-",14},
{ 28,"B4  vBUS",15},
{ 30,"B5   CC2",16},
{ 32,"B6    D+",17},
{ 34,"B7    D-",18},
{ 36,"B8  SBU2",19},
{ 38,"B9  vBUS",20},
{ 40,"B10 RX1-",21},
{ 42,"B11 RX1+",22},
{ 44,"B12  GND",23}
};



struct usbCright {
  byte pinnumber;      // 30 to 53 sensor pin addresses
  char* function;     // Text description of function and logical pin number
  byte refnum;           // Position of pin in rightside or leftside array

}

usbCright[24] = {
{51,"GND   A1",0},
{49,"TX1+  A2",1},
{47,"TX1-  A3",2},
{45,"vBUS  A4",3},
{62,"CC1   A5",4},
{63,"D+    A6",5},
{64,"D-    A7",6},
{65,"SBU1  A8",7},
{66,"vBUS  A9",8},
{67,"RX2- A10",9},
{68,"RX2+ A11",10},
{69,"GND  A12",11},
{23,"GND   B1",12},
{25,"TX2+  B2",13},
{27,"TX2-  B3",14},
{29,"vBUS  B4",15},
{31,"CC2   B5",16},
{33,"D+    B6",17},
{35,"D-    B7",18},
{37,"SBU2  B8",19},
{39,"vBUS  B9",20},
{41,"RX1- B10",21},
{43,"RX1+ B11",22},
{53,"GND  B12",23}
};

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.