Skip to main content
added 152 characters in body
Source Link

If you don't know how many data points will be recorded, look into vectors or an external storage device. Alternatively you could use a circular array if you don't mind losing recorded data after a while.

If you know how many data points will be recorded, a basic array will suffice.

As for excluding invalid values:

// Keep trying to get a valid data point 
While (RangeInCentimeters > 512 && RangeInCentimeters < 400)
{
 delay(1000200);  // The minimum value of this delay depends on the sample rate of your sensor
 RangeInCentimeters = ultrasonic.MeasureInCentimeters();
}

//... Store data to array/linked list/etc

I changed your max range to 512 because this is likely the max real value (2^9 = 512).

If you don't know how many data points will be recorded, look into vectors or an external storage device. Alternatively you could use a circular array if you don't mind losing recorded data after a while.

If you know how many data points will be recorded, a basic array will suffice.

As for excluding invalid values:

While (RangeInCentimeters > 512)
{
 delay(1000);
 RangeInCentimeters = ultrasonic.MeasureInCentimeters();
}

//... Store data to array/linked list/etc

I changed your max range to 512 because this is likely the max real value (2^9 = 512).

If you don't know how many data points will be recorded, look into vectors or an external storage device. Alternatively you could use a circular array if you don't mind losing recorded data after a while.

If you know how many data points will be recorded, a basic array will suffice.

As for excluding invalid values:

// Keep trying to get a valid data point 
While (RangeInCentimeters > 512 && RangeInCentimeters < 400)
{
 delay(200);  // The minimum value of this delay depends on the sample rate of your sensor
 RangeInCentimeters = ultrasonic.MeasureInCentimeters();
}

//... Store data to array/linked list/etc

I changed your max range to 512 because this is likely the max real value (2^9 = 512).

deleted 28 characters in body
Source Link

As far as I am aware there is no std::vector equivalent for Arduino, but for your purposes making a basic linked list should suffice.

If the sensor is intended for constant operation you don't know how many data points will need some sort ofbe recorded, look into vectors or an external storage for that data - the Arduino only has so much memory to work withdevice. YouAlternatively you could get around this by creatinguse a circular array, but this comes at the cost ofcircular array if you don't mind losing yourrecorded data after thea while.

If you know how many data points will be recorded, a basic array has filled upwill suffice.

As for excluding invalid values:

While (RangeInCentimeters > 512)
{
 delay(1000);
 RangeInCentimeters = ultrasonic.MeasureInCentimeters();
}

//... Store data to array/linked list/etc

I changed your max range to 512 because this is likely the max real value (2^9 = 512).

As far as I am aware there is no std::vector equivalent for Arduino, but for your purposes making a basic linked list should suffice.

If the sensor is intended for constant operation you will need some sort of external storage for that data - the Arduino only has so much memory to work with. You could get around this by creating a circular array, but this comes at the cost of losing your data after the array has filled up.

As for excluding invalid values:

While (RangeInCentimeters > 512)
{
 delay(1000);
 RangeInCentimeters = ultrasonic.MeasureInCentimeters();
}

//... Store data to array/linked list/etc

I changed your max range to 512 because this is likely the max real value (2^9 = 512).

If you don't know how many data points will be recorded, look into vectors or an external storage device. Alternatively you could use a circular array if you don't mind losing recorded data after a while.

If you know how many data points will be recorded, a basic array will suffice.

As for excluding invalid values:

While (RangeInCentimeters > 512)
{
 delay(1000);
 RangeInCentimeters = ultrasonic.MeasureInCentimeters();
}

//... Store data to array/linked list/etc

I changed your max range to 512 because this is likely the max real value (2^9 = 512).

added 228 characters in body
Source Link

As far as I am aware there is no std::vector equivalent for Arduino, but for your purposes making a basic linked list should suffice.

If the sensor is intended for constant operation you will need some sort of external storage for that data - the Arduino only has so much memory to work with. You could get around this by creating a circular array, but this comes at the cost of losing your data after the array has filled up.

As for excluding invalid values:

While (RangeInCentimeters > 512)
{
 delay(1000);
 RangeInCentimeters = ultrasonic.MeasureInCentimeters();
}

//... Store data to array/linked list/etc

WhileI changed your max range to 512 because this is likely the max real value (RangeInCentimeters >2^9 = 512).

As far as I am aware there is no std::vector equivalent for Arduino, but for your purposes making a basic linked list should suffice.

If the sensor is intended for constant operation you will need some sort of external storage for that data - the Arduino only has so much memory to work with. You could get around this by creating a circular array, but this comes at the cost of losing your data after the array has filled up.

As for excluding invalid values:

While (RangeInCentimeters > 512)

As far as I am aware there is no std::vector equivalent for Arduino, but for your purposes making a basic linked list should suffice.

If the sensor is intended for constant operation you will need some sort of external storage for that data - the Arduino only has so much memory to work with. You could get around this by creating a circular array, but this comes at the cost of losing your data after the array has filled up.

As for excluding invalid values:

While (RangeInCentimeters > 512)
{
 delay(1000);
 RangeInCentimeters = ultrasonic.MeasureInCentimeters();
}

//... Store data to array/linked list/etc

I changed your max range to 512 because this is likely the max real value (2^9 = 512).

Source Link
Loading