GY-63_MS5611/libraries/DEVRANDOM/examples/DEVRANDOM_demo/DEVRANDOM_demo.ino

139 lines
2.4 KiB
Arduino
Raw Normal View History

2021-01-29 06:31:58 -05:00
//
// FILE: DEVRANDOM_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// DATE: 2020-06-23
//
2021-12-15 13:48:19 -05:00
2021-01-29 06:31:58 -05:00
#include "DEVRANDOM.h"
DEVRANDOM dr;
uint32_t i = 0, start, stop;
volatile int x;
2021-12-15 13:48:19 -05:00
2021-01-29 06:31:58 -05:00
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.println();
2022-07-03 14:27:42 -04:00
Serial.println("Reseeding compile time");
start = micros();
dr.print(__FILE__);
dr.print(__DATE__);
dr.print(__TIME__);
dr.print(PI);
stop = micros();
Serial.print("reseeding: ");
Serial.println(stop - start);
Serial.println();
delay(1000);
Serial.println("Build in random");
dr.useRandom();
i = 0;
2021-01-29 06:31:58 -05:00
start = millis();
while (millis() - start < 1000)
{
x = dr.read();
i++;
}
2022-07-03 14:27:42 -04:00
Serial.print("nrs per second: ");
2021-01-29 06:31:58 -05:00
Serial.println(i);
Serial.println(x);
2022-07-03 14:27:42 -04:00
Serial.println();
2021-01-29 06:31:58 -05:00
delay(1000);
2022-07-03 14:27:42 -04:00
Serial.println("DigitalRead");
dr.useDigitalRead(4);
i = 0;
2021-01-29 06:31:58 -05:00
start = millis();
while (millis() - start < 1000)
{
x = dr.read();
i++;
}
Serial.print("nrs per second: ");
Serial.println(i);
Serial.println(x);
2022-07-03 14:27:42 -04:00
Serial.println();
2021-01-29 06:31:58 -05:00
delay(1000);
2022-07-03 14:27:42 -04:00
Serial.println("AnalogRead");
dr.useAnalogRead(A0);
i = 0;
2021-01-29 06:31:58 -05:00
start = millis();
while (millis() - start < 1000)
{
x = dr.read();
i++;
}
Serial.print("nrs per second: ");
Serial.println(i);
Serial.println(x);
2022-07-03 14:27:42 -04:00
Serial.println();
2021-01-29 06:31:58 -05:00
delay(1000);
2022-07-03 14:27:42 -04:00
Serial.println("MARSAGLIA");
dr.useMarsaglia();
2021-01-29 06:31:58 -05:00
i = 0;
2022-07-03 14:27:42 -04:00
start = millis();
while (millis() - start < 1000)
{
x = dr.read();
i++;
}
Serial.print("nrs per second: ");
Serial.println(i);
Serial.println(x);
Serial.println();
delay(1000);
2021-01-29 06:31:58 -05:00
// uint32_t x;
// fscanf((FILE*)&dr, "%lu", &x); // fails on ESP32
// Serial.print("UINT32: ");
// Serial.println(x, HEX);
// uint16_t y;
// fscanf((FILE*)&dr, "%u", &y); // fails on ESP32
// Serial.print("UINT16: ");
// Serial.println(y, HEX);
2021-01-29 06:31:58 -05:00
2022-07-03 14:27:42 -04:00
// float f;
// fscanf((FILE*)&dr, "%e", &f); // does not work on UNO.
// Serial.print("FLOAT: ");
// Serial.println(f, 4);
//
// char str[24];
// fscanf((FILE*)&dr, "%20s", str); // "works, but unusable garbage"
// Serial.print("STRING: ");
// Serial.println(str);
2021-01-29 06:31:58 -05:00
2022-07-03 14:27:42 -04:00
// reset i counter for loop()
Serial.println();
i = 0;
2021-01-29 06:31:58 -05:00
delay(1000);
}
2021-12-15 13:48:19 -05:00
2021-01-29 06:31:58 -05:00
void loop()
{
i++;
if (dr.available())
{
Serial.print("\t");
Serial.print(dr.read());
if ((i % 10) == 9 ) Serial.println();
}
delay(100);
}
2021-12-15 13:48:19 -05:00
// -- END OF FILE --