// Increment 64 bits counter as fast as possible.
// Press the button to show the value.
// Forum: https://forum.arduino.cc/t/sum-of-float-variables-differing-by-10-8/1253425/18
// This Wokwi project: https://wokwi.com/projects/396560196465457153
uint64_t counter;
unsigned long previousMillis;
const unsigned long interval = 1000;
volatile bool flag;
void setup()
{
Serial.begin(115200);
Serial.println("Press button to show counter value");
pinMode(2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2),showNow,FALLING);
}
void loop()
{
counter++;
if(flag)
{
byte buffer[21];
buffer[20] = '\0';
uint64_t copy = counter;
for(int i=19; i>=0; i--)
{
int digit = copy % 10;
copy /= 10;
buffer[i] = (byte) (digit + '0');
}
Serial.println((char *)buffer);
flag = false;
}
}
void showNow()
{
flag = true;
}
Press button to show counter value