GY-63_MS5611/libraries/MultiMap/examples/multimap_distance/multimap_distance.ino

52 lines
941 B
Arduino
Raw Normal View History

2020-11-27 05:20:37 -05:00
//
// FILE: multimap_distance.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// DATE: 2020-04-09
//
2021-12-22 06:10:05 -05:00
// example simulates the lookup graph of a distance sensor
2020-11-27 05:20:37 -05:00
2021-05-28 07:39:42 -04:00
2021-01-29 06:31:58 -05:00
#include "MultiMap.h"
2020-11-27 05:20:37 -05:00
2021-05-28 07:39:42 -04:00
2020-11-27 05:20:37 -05:00
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.println();
for (int i = 80; i < 512; i++)
{
float distance = sharp2cm(i);
// Serial.print('\t');
// Serial.print(i);
// Serial.print('\t');
Serial.println(distance, 1);
}
Serial.println("Done...");
}
2021-05-28 07:39:42 -04:00
2020-11-27 05:20:37 -05:00
void loop()
{
}
// for a sharp distance range finder
float sharp2cm(int val)
{
// out[] holds the distances in cm
float out[] = {150, 140, 130, 120, 110, 100, 90, 80, 70, 60, 50, 40, 30, 20};
// in[] holds the measured analogRead() values for that distance
float in[] = { 90, 97, 105, 113, 124, 134, 147, 164, 185, 218, 255, 317, 408, 506};
float dist = multiMap<float>(val, in, out, 14);
return dist;
}
2021-05-28 07:39:42 -04:00
2020-11-27 05:20:37 -05:00
// -- END OF FILE --
2021-12-22 06:10:05 -05:00