Comments (3)
initial version
//
// FILE: multimap_reverse_logarithmic.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// DATE: 2023-06-23
#include "MultiMap.h"
long in[10] = { 0, 150, 300, 550, 850, 970, 1009, 1017, 1021, 1023 };
long rlog10[10] = { 1023, 1000, 972, 909, 761, 586, 390, 264, 102, 0};
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.println();
delay(10); // make sure print has ended
for (int i = 0; i < 1024; i++)
{
int y = multiMap<long>(i, in, rlog10, 10);
Serial.print(i);
Serial.print("\t");
Serial.print(y);
Serial.println();
}
Serial.println();
delay(5000);
}
void loop()
{
int raw = analogRead(A0);
int val = multiMap<long>(raw, in, rlog10, 10);
Serial.print(raw);
Serial.print("\t");
Serial.print(val);
Serial.println();
delay(10);
}
// -- END OF FILE --
from multimap.
Update, with performance measurement
factor 3 when using multimap (size 10)
TIME MM: 62204
TIME FUNC: 194368
FACTOR: 3.12
//
// FILE: multimap_reverse_logarithmic.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// DATE: 2023-06-23
#include "MultiMap.h"
long in[10] = { 0, 150, 300, 550, 850, 970, 1009, 1017, 1021, 1023 };
long rlog10[10] = { 1023, 1000, 972, 909, 761, 586, 390, 264, 102, 0};
// as formula
int revlog10(int raw)
{
return round((1023 / 3.01) * log10(1023 - raw));
}
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.println();
delay(10); // make sure print has ended
performance();
delay(5000);
for (int i = 0; i < 1024; i++)
{
int y = multiMap<long>(i, in, rlog10, 10);
Serial.print(i);
Serial.print("\t");
Serial.print(y);
Serial.print("\t");
Serial.print(revlog10(i));
Serial.println();
}
Serial.println();
delay(5000);
}
void loop()
{
int raw = analogRead(A0);
int val = multiMap<long>(raw, in, rlog10, 10);
Serial.print(raw);
Serial.print("\t");
Serial.print(val);
Serial.println();
delay(10);
}
void performance()
{
uint32_t start, dur1, dur2;
volatile int x;
start = micros();
for (int i = 0; i < 1024; i++)
{
x = multiMap<long>(i, in, rlog10, 10);
}
dur1 = micros() - start;
Serial.print("TIME MM: \t");
Serial.println(dur1);
delay(100);
start = micros();
for (int i = 0; i < 1024; i++)
{
x = revlog10(i);
}
dur2 = micros() - start;
Serial.print("TIME FUNC: \t");
Serial.println(dur2);
Serial.print("FACTOR: \t");
Serial.println(1.0 * dur2 / dur1);
Serial.println();
delay(100);
}
// -- END OF FILE --
from multimap.
Added as example in version 0.1.7
from multimap.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from multimap.