system
April 5, 2014, 9:26am
#1
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(){}
Robin2
April 5, 2014, 11:42am
#3
@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
system
April 5, 2014, 11:55am
#4
Thanks a lot both Much appreciated
I would use yours Robin because I can understand it better
system
April 5, 2014, 11:57am
#5
If the nth element in an array has a known value, there is no reason to use an array.
system
April 5, 2014, 12:00pm
#6
I must use an array because I need it for the Histogram library
Robin2
April 5, 2014, 6:16pm
#7
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