Using Increment with Arrays

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

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(" ");

}

You can't use ++ this way. Create a loop to go over the elements and actually increase them one by one.

igendel:
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. So it increments 1 in every 20 secs.)

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

How can I use loop command in this code?

I'm not sure I understand... do you mean you want to do different kinds of measurements each time - for example, measure heat every single hour, but measure humidity only once every two hours?

If so, you could probably do with a single integer. Let's say it's called H and it represents full hours.
every time it changes (by your code of course), do this:

  1. Measure heat
  2. If H divides into 2 without reminder (i.e. H % 2 == 0), it means two hours have passed - measure humidity...

cagancelik:
I want store store humidity, heat and pressure information every 1,2,3,4 and 5 hours.

So surely you only need one clock?

If you have several appointments to keep in the day, do you need a separate clock for each of them? Of course not, that would be daft.

If you have a 5 element array you can (for example) set the value of each element to 27 like this

int myNumber = 27;
for (byte n = 0; n < 5; n++) {
   myArray[n] = myNumber;
}

If you want to keep time over a long period you will need to use a Real Time Clock module because the Arduino millis() function is not accurate enough.

Do NOT use the delay() function in your code. If you want to manage small periods of time use millis() as illustrated in several things at a time

...R

igendel:
I'm not sure I understand... do you mean you want to do different kinds of measurements each time - for example, measure heat every single hour, but measure humidity only once every two hours?

If so, you could probably do with a single integer. Let's say it's called H and it represents full hours.
every time it changes (by your code of course), do this:

  1. Measure heat
  2. If H divides into 2 without reminder (i.e. H % 2 == 0), it means two hours have passed - measure humidity...

No. For first hour, I use first integer in the array. For second i use second, for third, third array... it goes like that till 5.

If I don't do it like that, the columns I created on the 5110 LCD, which shows measurements for the first, second, third and fourth hours are not updated before fifth hour. I hope I made myself clear.

I've spent hours and hours on this code, I really tried lots of ways to do it and they all failed to deliver. Believe I wouldn't do it if it wasn't necessary.

But my programming skills aren't good. So if you would like to suggest a better way, I'm all ears.

Delta_G:
Maybe if you posted this code where we could see it, then someone could help you with it instead of just stabbing at the dark?

Sure, here you go. It's in Turkish though. I tried to translate some parts quickly but the rest of the code is in Turkish. Here are some helpful translations:

nem = humidity
sicaklik=heat
basinc=pressure
zaman=time
tahmin=estimation
çizelge=chart (nem çizelgesi = humidity chart)

Some parts might look very confusing and that's because you're not familiar with the whole thing. I spent so much time and wrote this thing by trial and error way. I fiddled with so many little things in there but I feel comfortable when I see the it because I know what each piece of code does individually.

It won't fit in this post. So I'm attaching it here as a text file.

thecode.txt (13.5 KB)