// modified from https://wokwi.com/arduino/libraries/LiquidCrystal_I2C/HelloWorld
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print("Speed test");
Serial.begin(115200);
delay(1000);
}
void loop() {
scrollLcd();
LoopCounter();
}
void scrollLcd()
{
const uint32_t interval = 2000;
static uint32_t last;
uint32_t now = micros();
if (now - last >= interval) {
last = now;
static byte row = 0;
static byte col = 0;
static byte val = 0;
lcd.setCursor(col, row);
lcd.print((char)('0' + val));
if (++col > 19) {
col = 0;
++row;
};
if (row > 3) {
row = 0;
++val;
}
if (val > 10 + 26 * 2) val = 0;
}
}
void LoopCounter() // tells the average response speed of void loop()
// code modified from https://forum.arduino.cc/t/while-loop-as-a-condition-for-limit-switches/963899/11
{ // inside a function, static variables keep their value from run to run
const unsigned long microsInOneSecond=1000000UL;
static unsigned long count, countStartMicros; // only this function sees these
count++; // adds 1 to count after any use in an expression, here it just adds 1.
if ( micros() - countStartMicros >= microsInOneSecond ) // 1 second
{
countStartMicros += microsInOneSecond; // for a regular second
Serial.println( count ); // 32-bit binary into decimal text = many micros
count = 0; // don't forget to reset the counter
}
}