GY-63_MS5611/libraries/GAMMA/examples/gammaFast/gammaFast.ino

97 lines
1.9 KiB
Arduino
Raw Normal View History

2021-01-29 06:31:58 -05:00
//
2021-11-02 10:15:11 -04:00
// FILE: gammaFast.ino
2021-01-29 06:31:58 -05:00
// AUTHOR: Rob Tillaart
// PURPOSE: demo
#include "gamma.h"
2021-11-02 10:15:11 -04:00
2021-01-29 06:31:58 -05:00
GAMMA gt1(256);
// fastGamma is based upon values found with GAMMA(8).setGamma(2.8);
2021-11-02 10:15:11 -04:00
// it is however not fast enough...
// binary search
2021-01-29 06:31:58 -05:00
int fastGamma(uint8_t idx)
{
2021-11-02 10:15:11 -04:00
if (idx < 128)
{
if (idx < 64)
{
if (idx < 32) return map(idx, 0, 31, 0, 1);
return map(idx, 32, 63, 1, 5);
}
else
{
if (idx < 96) return map(idx, 64, 95, 5, 17);
return map(idx, 96, 127, 17, 37);
}
}
if (idx < 192)
{
if (idx < 160) return map(idx, 128, 159, 37, 69);
return map(idx, 160, 191, 69, 115);
}
2021-01-29 06:31:58 -05:00
if (idx < 224) return map(idx, 192, 223, 115, 177);
return map(idx, 224, 255, 177, 255);
}
void setup()
{
Serial.begin(115200);
2022-07-25 09:25:14 -04:00
Serial.println();
Serial.println(__FILE__);
Serial.print("GAMMA_LIB_VERSION: ");
Serial.println(GAMMA_LIB_VERSION);
2021-01-29 06:31:58 -05:00
2021-11-02 10:15:11 -04:00
gt1.begin();
2021-01-29 06:31:58 -05:00
gt1.setGamma(2.8);
2021-11-02 10:15:11 -04:00
Serial.println("\n\ttest fastGamma()");
Serial.println("\ti \tgt1[] \tfast \tdelta");
for (int i = 0; i < 256; i ++ )
2021-01-29 06:31:58 -05:00
{
2021-11-02 10:15:11 -04:00
Serial.print('\t');
2021-01-29 06:31:58 -05:00
Serial.print(i);
Serial.print('\t');
Serial.print(gt1[i]);
Serial.print('\t');
2021-11-02 10:15:11 -04:00
Serial.print(fastGamma(i));
Serial.print('\t');
Serial.print(gt1[i] - fastGamma(i));
2021-01-29 06:31:58 -05:00
Serial.println();
}
2021-11-02 10:15:11 -04:00
volatile uint32_t x = 0;
2021-01-29 06:31:58 -05:00
uint32_t start = micros();
for (int i = 0; i < 256; i++) x += gt1[i];
uint32_t d1 = micros() - start;
2021-11-02 10:15:11 -04:00
Serial.println();
Serial.print(" 256 x gt1[i] : ");
2021-01-29 06:31:58 -05:00
Serial.println(d1);
2021-11-02 10:15:11 -04:00
Serial.print(" x : ");
Serial.println(x);
2021-01-29 06:31:58 -05:00
delay(10);
2021-11-02 10:15:11 -04:00
x = 0;
2021-01-29 06:31:58 -05:00
start = micros();
for (int i = 0; i < 256; i++) x += fastGamma(i);
d1 = micros() - start;
2021-11-02 10:15:11 -04:00
Serial.print(" 256 x fast : ");
2021-01-29 06:31:58 -05:00
Serial.println(d1);
2021-11-02 10:15:11 -04:00
Serial.print(" x : ");
Serial.println(x);
2021-01-29 06:31:58 -05:00
delay(10);
2021-11-02 10:15:11 -04:00
Serial.println("\ndone...");
2021-01-29 06:31:58 -05:00
}
void loop()
{
}
2021-11-02 10:15:11 -04:00
2021-01-29 06:31:58 -05:00
// -- END OF FILE --