Go Down

Topic: Using Increment with Arrays (Read 11 times) previous topic - next topic

I would like my integers in an Array to increase one by one. But I always get 0. What am I doing wrong here?


Code: [Select]
int myArray[5] = {0,0,0,0,0};

void setup() {
Serial.begin(9600);

}

void loop() {
++myArray[1,2,3,4,5];

 Serial.print(myArray[0]);
 Serial.print(" ");
  Serial.print(myArray[1]);
   Serial.print(" ");
   Serial.print(myArray[2]);
    Serial.print(" ");
    Serial.print(myArray[3]);
     Serial.print(" ");
     Serial.print(myArray[4]);
      Serial.println(" ");

}

igendel

You can't use ++ this way. Create a loop to go over the elements and actually increase them one by one.
My Adventures in the Making:
http://www.idogendel.com/en

You can't use ++ this way. Create a loop to go over the elements and actually increase them one by one.
Here's what I'm intending to do. This is a part of mini weather station project. I want store store humidity, heat and pressure information every 1,2,3,4 and 5 hours. To measure time, I decided to create some integer arrays that increment one by one in every 20 secs. (There are several delay commands in void loop function, so it takes about 20 secs to loop and start again.)

Then I wrote switch case code, if the integer in the arrays reach ".." number it means ".." hour passed so store the the heat, humidity and pressure etc...

How can I use loop command in this code?

Go Up