2021-01-29 06:31:58 -05:00
|
|
|
//
|
|
|
|
// FILE: microSeconds.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// PURPOSE: demo
|
|
|
|
// URL: https://github.com/RobTillaart/timing
|
|
|
|
|
2021-05-28 07:47:03 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
#include "timing.h"
|
|
|
|
#include "printHelpers.h" // https://github.com/RobTillaart/printHelpers
|
|
|
|
|
2021-05-28 07:47:03 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println(__FILE__);
|
|
|
|
delay(10);
|
|
|
|
|
|
|
|
microSeconds ms; // starts at zero
|
|
|
|
uint64_t big = fibonaci(91); // 91 is the max!
|
|
|
|
uint32_t x = micros();
|
|
|
|
uint32_t y = ms.now();
|
|
|
|
Serial.print("micros():\t");
|
|
|
|
Serial.println(x);
|
|
|
|
Serial.print("ms.now(): \t");
|
|
|
|
Serial.println(y);
|
|
|
|
Serial.print(" fib(91): \t");
|
|
|
|
Serial.println(print64(big));
|
|
|
|
|
|
|
|
Serial.println("\nDone...");
|
|
|
|
}
|
|
|
|
|
2021-05-28 07:47:03 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-05-28 07:47:03 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
uint64_t fibonaci(uint32_t n)
|
|
|
|
{
|
|
|
|
uint64_t p = 0;
|
|
|
|
uint64_t q = 1;
|
|
|
|
uint64_t t;
|
|
|
|
if (n == 0) return 0;
|
|
|
|
if (n == 1) return 1;
|
|
|
|
for (uint32_t i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
t = p;
|
|
|
|
p = q;
|
|
|
|
q += t;
|
|
|
|
// Serial.print(i);
|
|
|
|
// Serial.print("\t");
|
|
|
|
// Serial.println(print64(q));
|
|
|
|
}
|
|
|
|
return q;
|
|
|
|
}
|
|
|
|
|
2021-05-28 07:47:03 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
// -- END OF FILE --
|
2021-12-29 05:16:45 -05:00
|
|
|
|