0

I have a problem. My code for Arduino is:

void count (int a){
  if (a == 0) {
    int led_pin [4] = {3, 4, 5, 6};
  }

  else{
    int led_pin [2] = {4, 5, 6, 9};
  }

  for (int i = 0; i <= 7; i++){
    digitalWrite(led_pin[i], HIGH);
  }
}

and I get output:

'led_pin' was not declared in this scope

How to declared array or change values of array?

1

1 Answer 1

2

You are getting the error because you have bounded the scope of your led_pin variable inside the if and else condition.

Also you are trying to change the whole variable, you should not do that.

Try this out.

void count(int a){
    int led_pin[2][4]={{3,4,5,6},{4,5,6,9}};
    if( a !=0)
    {
        a=1;
    }
    for(int i=0;i<4;i++) //I don't know why you used 7 in your code.
    {
        digitalWrite(led_pin[a][i],HIGH);
    }
}

I hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.