Creating variables with a loop?

i was wondering how i can make a loop that creates variables in Arduino, and bonus question: how can i make those variables global?

  for (int i=0; i <= 24; i++){
  bool+"a"+i;}
  a24= true;
  a25 = false;

this is what i tried,

You can't :slight_smile:

Just make an array

bool varA[25];

varA[24] = true;
varA[25] = false;

if i use the array to make the variables in bool form, will they automatically get false as value? because my plan is to only change the value of those who need to be true

zedpython:
if i use the array to make the variables in bool form, will they automatically get false as value? because my plan is to only change the value of those who need to be true

Boolean globals will be given a value of false when declared unless you initialise them as true.

Just make an array

bool varA[25];

varA[24] = true;
varA[25] = false;

Writing past the end of the array is NOT a good idea. An array with 25 elements has a last position of 24. I know that you know that.

True, in my deference, I only looked at the parameters of the for loop (<= 24) when I declared the array :confused:

@zedpython, Even if they are true, after that you can loop over them in setup() to set them to whatever you like :slight_smile:

after i do bool varA[25];

how can i assign all 25 as output pins?

zedpython:
after i do bool varA[25];

how can i assign all 25 as output pins?

You mean, write the values to output pins?

yes assign them as outputs

zedpython:
yes assign them as outputs

That was not an answer to the question.

Do you want to output the values from the array to a single pin or something else ?

It would help to have a general description of what you are doing so that answers can be given in context.

A variable isn't an output.

But to assign something to it just do

varA[4] = true;

//or loop over them like you wanted:
for(byte i = 0; i < 24; i++){
  //now you can index the variable in the array :0
  varA[i] = (i % 2); //True for odd, false for even
}

something like pinMode(A[25], OUTPUT);
i want a1 to be an output pin on the arduino, a2 another pin all the way until pin 25

zedpython:
something like pinMode(A[25], OUTPUT);
i want a1 to be an output pin on the arduino, a2 another pin all the way until pin 25

Put the pin numbers in an array and iterate through it to set the pinMode() of each array

const byte outPins[] = {10, 11, 12};
const byte NUMBER_OF_PINS = sizeof(outPins) / sizeof(outPins[0]);

void setup()
{
  for (int pin = 0 ; pin < NUMBER_OF_PINS; pin ++)
  {
    pinMode(outPins[pin], OUTPUT);
  }
}

void loop()
{
}