2020-11-27 05:20:37 -05:00
|
|
|
//
|
|
|
|
// FILE: multimap_distance.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
2021-01-29 06:31:58 -05:00
|
|
|
// VERSION: 0.1.1
|
2020-11-27 05:20:37 -05:00
|
|
|
// PURPOSE: demo
|
|
|
|
// DATE: 2020-04-09
|
|
|
|
//
|
|
|
|
|
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 --
|