Can somebody help me?

Hello, I’m getting started and I was trying to create an array, but when I try to compile I have this messege: “array must be initialized with a brace-enclosed initializer”
This is the code:

const int Pulsador = 9;
byte Oruga[8] = (1,2,3,4,5,6,7,8);
boolean EstadoPulsador;
boolean Valor = LOW;
byte i;
void setup() {
pinMode(Pulsador, INPUT);
for (i=0, i<8, i++){
pinMode(Oruga*, OUTPUT);*

  • }*
    }
    void loop() {
  • EstadoPulsador=digitalRead(Pulsador);*
  • if EstadoPulsador==HIGH{*
  • for (i=0, i<8, i++){*
  • Valor!=Valor;*
    _ digitalWrite(Oruga*, valor);_
    _
    }_
    _
    }_
    _
    }[/quote]_
    Then I try writing this, I dont have that problem now, but it didnt compile anyway
    _
    > const int Pulsador = 9;_
    _
    > int Oruga;_
    _
    > boolean EstadoPulsador;_
    _
    > boolean Valor = LOW;_
    _
    > int i;_
    _
    > void setup() {_
    _
    > pinMode(Pulsador, INPUT);_
    _
    > for (Oruga=1, Oruga<=8, Oruga++){_
    _
    > pinMode(Oruga, OUTPUT);_
    _
    > }_
    _
    > }_
    _
    >_
    _
    > void loop() {_
    _
    > EstadoPulsador=digitalRead(Pulsador);_
    _
    > if (EstadoPulsador==HIGH){_
    _
    > for (Oruga=1, Oruga<=8, Oruga++) {_
    _
    > Valor!=Valor;_
    _
    > digitalWrite(Oruga, Valor);_
    _
    > }_
    _
    > }_
    _
    > }*_
    Sorry if my english is bad, I speak in spanish

byte Oruga[8] = (1,2,3,4,5,6,7,8);
Needs to be
byte Oruga[8] = {1,2,3,4,5,6,7,8};

{ } vs ( )

Also:

pinMode(Oruga, OUTPUT);
to
pinMode(Oruga[i], OUTPUT);

and

    for (Oruga=1, Oruga<=8, Oruga++) {
      Valor!=Valor;
      digitalWrite(Oruga, Valor);
    }
to
    for (i=1, i<=8, i++) {
      Valor!=Valor;
      digitalWrite(Oruga[i], Valor);
    }

Sorry, this should be:

    for (i=0, i<8, i++) {
      Valor!=Valor;
      digitalWrite(Oruga[i], Valor);
    }

as the array elements are Oruga[0] to Oruga[7]. There is no Oruga[8].

Thanks for answer me, It was a silly mistake I didn’t realize, from now on I’ll pay more attention, now this is the code:

const int Pulsador = 9;
int Oruga[8] = {1,2,3,4,5,6,7,8};
boolean EstadoPulsador;
boolean Valor = LOW;
byte i;
void setup() {
pinMode(Pulsador, INPUT);
for (i=0, i<8, i++){
pinMode(Oruga*, OUTPUT);*

  • }*
    }
    void loop() {
  • EstadoPulsador=digitalRead(Pulsador);*
  • if (EstadoPulsador==HIGH){*
  • Valor!=Valor;*
  • for (i=0, i<8, i++) {*
    _ digitalWrite(Oruga*, Valor);_
    _
    }_
    _
    }_
    _
    }[/quote]_
    but I can’t compile it, it says
    _
    > “expected ‘;’ before ‘)’ token”*_
    in the ‘for’ of the void loop, and if I add an ‘;’ It still send the same message

CrossRoads:

    for (i=0, i<8, i++) {

Valor!=Valor;
     digitalWrite(Oruga[i], Valor);
   }




_*as the array elements are Oruga[0] to Oruga[7]. There is no Oruga[8].*_

What am I missing here? Isn’t Valor loop invariant and the statement could be moved before the for loop is entered?

You should post the exact and entire error message. The error message includes information as to the location of the error (line number and location within the line).

for (i=0, i<8, i++){ Use semicolons, not commas in the for statements

 for (i=0; i<8; i++){

Oruga is an array, you need to access it element by element.
So in both setup() and loop(), it should use

Oruga[i]

and not just Oruga
Next time use </> button for code tags, perhaps the Quote tag is making the code appear funny.
I think the i is getting turned into italics when the code is copied here and mixing things up. Lets try x:

const byte Pulsador = 9; // byte vs int, value is <= 255
byte Oruga[8] = {1,2,3,4,5,6,7,8}; // byte vs int
boolean EstadoPulsador;
boolean Valor = LOW;
byte x;
void setup() {
  pinMode(Pulsador, INPUT);
  for (x=0; x<8; x++){ // need ; here and not '
    pinMode(Oruga[x], OUTPUT);
    }
}

void loop() {
  EstadoPulsador=digitalRead(Pulsador);
  if (EstadoPulsador==HIGH){
    Valor!=Valor;
    for (x=0; x<8; x++) { // ; vs , again
      digitalWrite(Oruga[x], Valor);
    }
  }
}

This is all the error message

Ejercicio4Oruga.ino: In function 'void setup()':
Ejercicio4Oruga:8: error: expected ';' before ')' token
Ejercicio4Oruga:9: error: expected primary-expression before '}' token
Ejercicio4Oruga:9: error: expected ';' before '}' token
Ejercicio4Oruga:9: error: expected primary-expression before '}' token
Ejercicio4Oruga:9: error: expected ')' before '}' token
Ejercicio4Oruga:9: error: expected primary-expression before '}' token
Ejercicio4Oruga:9: error: expected ';' before '}' token
Ejercicio4Oruga.ino: In function 'void loop()':
Ejercicio4Oruga:15: error: expected ';' before ')' token
Ejercicio4Oruga:16: error: expected primary-expression before '}' token
Ejercicio4Oruga:16: error: expected ';' before '}' token
Ejercicio4Oruga:16: error: expected primary-expression before '}' token
Ejercicio4Oruga:16: error: expected ')' before '}' token
Ejercicio4Oruga:16: error: expected primary-expression before '}' token
Ejercicio4Oruga:16: error: expected ';' before '}' token
expected ';' before ')' token

And this is the code, I write "Oruga " but it dissapeared when i post that.
```
*const int Pulsador = 9;
int Oruga[8] = {1,2,3,4,5,6,7,8};
boolean EstadoPulsador;
boolean Valor = LOW;
byte i;
void setup() {
  pinMode(Pulsador, INPUT);
  for (i=0, i<8, i++){
    pinMode(Oruga[i], OUTPUT);}}

void loop() {
  EstadoPulsador=digitalRead(Pulsador);
  if (EstadoPulsador==HIGH){
    Valor!=Valor;
    for (i=0, i<8, i++) {
      digitalWrite(Oruga[i], Valor);}}}*
```

for (i=0, i<8, i++) { should be for (i=0; i<8; i++) {

“;” vs “,”.

Try the corrected code in Reply #7.

Thanks everyone for help me, now I have solved the problem and learnt how to make arrays.