LED off, on, blinking, faster

This a code that can be used for turning a led on, blinking and blinking twice as fast.
I’ve made a adjustment of the debounce example.

Test_Blinking_faster_and_off.ino (1.88 KB)

Why do you need three variables to determine if the current pin state is, or is not, the same as the previous state?

That debouncing sketch you started from is probably the worst possible starting point.

Great code! Looked better than my first few sketches anyway. There are a few things I would change though: I would change the pin value types to bytes, rather than ints and I would try not to use longs whenever possible as they are large and usually unnecessarily so.

Time tracking related elements should be unsigned long, same as millis() and micros() return:

long t0;
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers

long freq1,Freq,i,freq2;

This hardly qualifies as great code. It doesn't even compile.

Pete

I was responding to Mike44449 who said it was "great code".

Pete