set 4 pins values a single variable?

Afternoon all,
I have been digging on this for a bit, not sure if I am not searching correctly, or if it is not possible.

I would like to create a variable that can be called later in the script that sets the output values of four different digital pins.

Is this possible, am I calling it a variable when I should be looking for something else?

Many thanking ewe's for your insight.
Jason

   const int VAR_T1_0
    // LIGHT Ones Column ZERO
    digitalWrite (PIN_T1A, LOW);
    digitalWrite (PIN_T1B, LOW);
    digitalWrite (PIN_T1C, LOW);
    digitalWrite (PIN_T1D, LOW);

More info please.
Always show us your current compete sketch. Use CTRL T to format the sketch. Please use code tags. Use the </> icon in the posting menu. [code] Paste sketch here. [/code]
.

The individual bits of a byte variable can store the states of up to 8 pins. You can set and clear bits by using the following statements:

   byte var, bit_number;
   var |= (1<<bit_number); //set bit_number (0 to 7)
   var &= ~(1<<bit_number);  //clear bit_number (0 to 7)

Check a bit and set state of a pin accordingly:

   byte state = var&(1<<bit_number);
   if (state) digitalWrite(pin, HIGH);
   else digitalWrite(pin,LOW);

Of course there are many other ways to accomplish the above.

Thank you for your reply.

Please see code below. What I would like to accomplish is to find a way to set four pins by calling one function/variable or what ever the proper code is (not sure what to call it at this point)

This would allow me to pre-define all 24 pins that I need to swith on and off to control four tubes. (only have code for two below).

Actual code below.

/*Begining of Auto generated code by Atmel studio */
#include <Arduino.h>

/*End of auto generated code by Atmel studio */


//Beginning of Auto generated function prototypes by Atmel Studio
//End of Auto generated function prototypes by Atmel Studio


// Tube HUND place FRONT
const int PIN_T1A = 2;         //PIN A
const int PIN_T1B = 3;         //PIN B
const int PIN_T1C = 4;         //PIN C
const int PIN_T1D = 5;         //PIN D

// Tube TENS Place FRONT
const int PIN_T2A = 6;         //PIN A
const int PIN_T2B = 7;         //PIN B
const int PIN_T2C = 8;         //PIN C
const int PIN_T2D = 9;         //PIN D

// Tube ONES Place FRONT
const int PIN_T3A = 10;         //PIN A
const int PIN_T3B = 11;         //PIN B
const int PIN_T3C = 12;         //PIN C
const int PIN_T3D = 13;         //PIN D

// Tube HUND place BACK
const int PIN_T4A = 22;         //PIN A
const int PIN_T4B = 23;         //PIN B
const int PIN_T4C = 24;         //PIN C
const int PIN_T4D = 25;         //PIN D

// Tube TENS Place BACK
const int PIN_T5A = 26;         //PIN A
const int PIN_T5B = 27;         //PIN B
const int PIN_T5C = 28;         //PIN C
const int PIN_T5D = 29;         //PIN D

// Tube ONES Place BACK
const int PIN_T6A = 30;         //PIN A
const int PIN_T6B = 31;         //PIN B
const int PIN_T6C = 32;         //PIN C
const int PIN_T6D = 33;         //PIN D




int VAR_D100;
int VAR_D100TensPos;


// the setup() method runs once, when the sketch starts

void setup() {
  // initialize the digital pin as an output.

  pinMode(PIN_T1A, OUTPUT);
  pinMode(PIN_T1B, OUTPUT);
  pinMode(PIN_T1C, OUTPUT);
  pinMode(PIN_T1D, OUTPUT);

  pinMode(PIN_T2A, OUTPUT);
  pinMode(PIN_T2B, OUTPUT);
  pinMode(PIN_T2C, OUTPUT);
  pinMode(PIN_T2D, OUTPUT);

  pinMode(PIN_T3A, OUTPUT);
  pinMode(PIN_T3B, OUTPUT);
  pinMode(PIN_T3C, OUTPUT);
  pinMode(PIN_T3D, OUTPUT);

  pinMode(PIN_T4A, OUTPUT);
  pinMode(PIN_T4B, OUTPUT);
  pinMode(PIN_T4C, OUTPUT);
  pinMode(PIN_T4D, OUTPUT);

  pinMode(PIN_T5A, OUTPUT);
  pinMode(PIN_T5B, OUTPUT);
  pinMode(PIN_T5C, OUTPUT);
  pinMode(PIN_T5D, OUTPUT);

  pinMode(PIN_T6A, OUTPUT);
  pinMode(PIN_T6B, OUTPUT);
  pinMode(PIN_T6C, OUTPUT);
  pinMode(PIN_T6D, OUTPUT);



  Serial.begin(9600);


}

void loop()
{
  int VAR_D100 = random(1, 101);
  Serial.print("D100 Roll - ");
  Serial.println(VAR_D100);
  delay(100);



  int VAR_D100OnesPos = VAR_D100 % 10;
  Serial.print("Ones - ");
  Serial.println(VAR_D100OnesPos);
  delay(100);


  int VAR_D100_Tens = VAR_D100 / 10;
  int VAR_D100_TensPos = VAR_D100_Tens % 10;
  Serial.print("Tens - ");
  Serial.println(VAR_D100_TensPos);
  delay(100);


  int VAR_D100_HundredsPos = VAR_D100 / 100;
  Serial.print("Hundreds - ");
  Serial.println(VAR_D100_HundredsPos);
  delay(100);

  if (VAR_D100OnesPos == 0)
  {
    // LIGHT 0
    digitalWrite (PIN_T1A, LOW);
    digitalWrite (PIN_T1B, LOW);
    digitalWrite (PIN_T1C, LOW);
    digitalWrite (PIN_T1D, LOW);
    delay(2000);
  }
  else if (VAR_D100OnesPos == 1)
  {
    // LIGHT 1
    digitalWrite (PIN_T1A, HIGH);
    digitalWrite (PIN_T1B, LOW);
    digitalWrite (PIN_T1C, LOW);
    digitalWrite (PIN_T1D, LOW);
    delay(2000);
  }
  else if (VAR_D100OnesPos == 2)
  {
    // LIGHT 2
    digitalWrite (PIN_T1A, LOW);
    digitalWrite (PIN_T1B, HIGH);
    digitalWrite (PIN_T1C, LOW);
    digitalWrite (PIN_T1D, LOW);
    delay(2000);
  }
  else if (VAR_D100OnesPos == 3)
  {
    // LIGHT 3
    digitalWrite (PIN_T1A, HIGH);
    digitalWrite (PIN_T1B, HIGH);
    digitalWrite (PIN_T1C, LOW);
    digitalWrite (PIN_T1D, LOW);
    delay(2000);
  }
  else if (VAR_D100OnesPos == 4)
  {
    // LIGHT 4
    digitalWrite (PIN_T1A, LOW);
    digitalWrite (PIN_T1B, LOW);
    digitalWrite (PIN_T1C, HIGH);
    digitalWrite (PIN_T1D, LOW);
    delay(2000);
  }
  else if (VAR_D100OnesPos == 5)
  {
    // LIGHT 5
    digitalWrite (PIN_T1A, HIGH);
    digitalWrite (PIN_T1B, LOW);
    digitalWrite (PIN_T1C, HIGH);
    digitalWrite (PIN_T1D, LOW);
    delay(2000);
  }
  else if (VAR_D100OnesPos == 6)
  {
    // LIGHT 6
    digitalWrite (PIN_T1A, LOW);
    digitalWrite (PIN_T1B, HIGH);
    digitalWrite (PIN_T1C, HIGH);
    digitalWrite (PIN_T1D, LOW);
    delay(2000);
  }
  else if (VAR_D100OnesPos == 7)
  {
    // LIGHT 7
    digitalWrite (PIN_T1A, HIGH);
    digitalWrite (PIN_T1B, HIGH);
    digitalWrite (PIN_T1C, HIGH);
    digitalWrite (PIN_T1D, LOW);
    delay(2000);
  }
  else if (VAR_D100OnesPos == 8)
  {
    // LIGHT 8
    digitalWrite (PIN_T1A, LOW);
    digitalWrite (PIN_T1B, LOW);
    digitalWrite (PIN_T1C, LOW);
    digitalWrite (PIN_T1D, HIGH);
    delay(2000);
  }
  else if (VAR_D100OnesPos == 9)
  {
    // LIGHT 9
    digitalWrite (PIN_T1A, HIGH);
    digitalWrite (PIN_T1B, LOW);
    digitalWrite (PIN_T1C, LOW);
    digitalWrite (PIN_T1D, HIGH);
    delay(2000);
  }
  if (VAR_D100_TensPos == 0)
  {
    // LIGHT 0
    digitalWrite (PIN_T2A, LOW);
    digitalWrite (PIN_T2B, LOW);
    digitalWrite (PIN_T2C, LOW);
    digitalWrite (PIN_T2D, LOW);
    delay(2000);
  }
  else if (VAR_D100_TensPos == 1)
  {
    // LIGHT 1
    digitalWrite (PIN_T2A, HIGH);
    digitalWrite (PIN_T2B, LOW);
    digitalWrite (PIN_T2C, LOW);
    digitalWrite (PIN_T2D, LOW);
    delay(2000);
  }
  else if (VAR_D100_TensPos == 2)
  {
    // LIGHT 2
    digitalWrite (PIN_T2A, LOW);
    digitalWrite (PIN_T2B, HIGH);
    digitalWrite (PIN_T2C, LOW);
    digitalWrite (PIN_T2D, LOW);
    delay(2000);
  }
  else if (VAR_D100_TensPos == 3)
  {
    // LIGHT 3
    digitalWrite (PIN_T2A, HIGH);
    digitalWrite (PIN_T2B, HIGH);
    digitalWrite (PIN_T2C, LOW);
    digitalWrite (PIN_T2D, LOW);
    delay(2000);
  }
  else if (VAR_D100_TensPos == 4)
  {
    // LIGHT 4
    digitalWrite (PIN_T2A, LOW);
    digitalWrite (PIN_T2B, LOW);
    digitalWrite (PIN_T2C, HIGH);
    digitalWrite (PIN_T2D, LOW);
    delay(2000);
  }
  else if (VAR_D100_TensPos == 5)
  {
    // LIGHT 5
    digitalWrite (PIN_T2A, HIGH);
    digitalWrite (PIN_T2B, LOW);
    digitalWrite (PIN_T2C, HIGH);
    digitalWrite (PIN_T2D, LOW);
    delay(2000);
  }
  else if (VAR_D100_TensPos == 6)
  {
    // LIGHT 6
    digitalWrite (PIN_T2A, LOW);
    digitalWrite (PIN_T2B, HIGH);
    digitalWrite (PIN_T2C, HIGH);
    digitalWrite (PIN_T2D, LOW);
    delay(2000);
  }
  else if (VAR_D100_TensPos == 7)
  {
    // LIGHT 7
    digitalWrite (PIN_T2A, HIGH);
    digitalWrite (PIN_T2B, HIGH);
    digitalWrite (PIN_T2C, HIGH);
    digitalWrite (PIN_T2D, LOW);
    delay(2000);
  }
  else if (VAR_D100_TensPos == 8)
  {
    // LIGHT 8
    digitalWrite (PIN_T2A, LOW);
    digitalWrite (PIN_T2B, LOW);
    digitalWrite (PIN_T2C, LOW);
    digitalWrite (PIN_T2D, HIGH);
    delay(2000);
  }
  else if (VAR_D100_TensPos == 9)
  {
    // LIGHT 9
    digitalWrite (PIN_T2A, HIGH);
    digitalWrite (PIN_T2B, LOW);
    digitalWrite (PIN_T2C, LOW);
    digitalWrite (PIN_T2D, HIGH);
    delay(2000);
  }




  else
    // NULL (Blank Tube)
    digitalWrite (PIN_T2A, HIGH);
  digitalWrite (PIN_T2B, HIGH);
  digitalWrite (PIN_T2C, HIGH);
  digitalWrite (PIN_T2D, HIGH);
}

jremington:
The individual bits of a byte variable can store the states of up to 8 pins. You can set and clear bits by using the following statements:

   byte var, bit_number;

var |= (1<<bit_number); //set bit_number (0 to 7)
  var &= ~(1<<bit_number);  //clear bit_number (0 to 7)




Check a bit and set state of a pin accordingly:



byte state = var&(1<<bit_number);
  if (state) digitalWrite(pin, HIGH);
  else digitalWrite(pin,LOW);




Of course there are [u]many[/u] other ways to accomplish the above.

Thank you,
I did see this earlier, I will have to struggle through it as it is beyond my knowledge level at this time. Hopefully I will be able to figure it out.
Regards,
Jason

Look up the Arduino bitRead() and bitWrite() functions.