Regular Spaced Array

Anyone can help me please. I want an array having the first value 0 and end value 16000 with element increment of 500 like the example below. However if possible I don't want to enter each value because it is not aesthetically pleasing and it get worse with higher end value!

double b = { 0, 500, 1000, 1500, 2000, 2500, 3000, ..............., 14000, 14500, 15000, 15500, 16000}

Sure you want double, I used int instead.

struct Foo{
  Foo() : value( count++ * 500 ) {}
  operator int &(){ return value; }
  int value;
  static int count;
};
int Foo::count = 0x00;

void setup(){
  
  Foo f[ 33 ];
  
  Serial.begin( 9600 );
  
  for( int i = 0x00 ; i < 33 ; ++i ){
    Serial.println( f[ i ] );
  }
}

void loop(){}

@pYro_65, that’s wonderfully complicated !

What about this

double b[33];

void setup() {
   byte curVal = 0;
   for (byte n = 0; n < 33; n ++) {
      b[n] = curVal;
      curVal += 500;
   }

  // other setup stuff

}

…R

Thanks a lot both :slight_smile: Much appreciated

I would use yours Robin because I can understand it better :wink:

If the nth element in an array has a known value, there is no reason to use an array.

I must use an array because I need it for the Histogram library

PaulS:
If the nth element in an array has a known value, there is no reason to use an array.

Very true. I made a similar point in another Thread - though I hadn’t thought of it quite like that.

…R