Filling an array with custom values

Hello!

I am trying to fill an array with 600 values to make a custom plot to display later. I want to make this values from different straight lines and i have made several for statements to fill it up, but when I print the array it is all filled with zeros, what am I doing wrong?


unsigned int Array[600];

void setup() {
  // put your setup code here, to run once:
  Fill_array();
  Serial.begin(9600);
}

void loop() {
  for (int t = 0; t < 600; t++) {
    int plot = (Array[t]);
    Serial.print(plot);
  }
}

void Fill_Array() {

  for (int t = 0; t == 170; t++) {
    int calc = -0.35 * t + 200;
    Array[t] = int(calc);
  }
  for (int t = 171; t == 256; t++) {
    float calc = 0.35 * t + 50;
    Array[t] = int(calc);
  }
  for (int t = 257; t == 341; t++) {
    float calc = -0.8 * t + 354;
    Array[t] = int(calc);
  }
  for (int t = 342; t == 426; t++) {
    float calc = 0.12 * t + 29;
    Array[t] = int(calc);
  }
  for (int t = 427; t == 511; t++) {
    float calc = -0.38 * t + 232;
    Array[t] = int(calc);
  }
  for (int t = 512; t == 600; t++) {
    float calc = -0.23 * t + 166;
    Array[t] = int(calc);
  }
}

All the conditions in the fors are wrong, none will be entered.

t == 170

What do you think this does ?

should be

  for (int t = 0; t <= 170; t++) {
    Array[t] = -0.35 * t + 200;
  }

Use serial print() while you are filling the arrays. Show the index value and the computed values.
Paul

Most of the conditions in the fors are wrong. :wink:

I though when "t" reaches 170 it should exit the for statement... but I see I was very wrong

You are now an expert in using for( ).

Yeah, I only looked at the failing filling fors. :grinning:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.