Hi Nick
Most of the strange coding you’ve noted was my attempt
to figure out where the code was going bad.
As I said, it would sometimes just stop for a second or so
and then continue. I was thinking it had to be something
in the code that I was doing.
I was thinking that maybe A-B wasn’t the same as A + ~B +1 and
if I coded it in a way that there could be no error, maybe I’d find
the problem.
The while watching it, one time it stopped right in the middle of the
code that blinks the blue light. The blue LED stayed on for about a second
and then went out for about a second or so. After that things continued.
Since the only thing that could delay thing that could cause the blue led
to stay on was the delay() function, I made this post and the other
about subtraction of unsigned longs.
The code was in the middle of debugging to see what was causing the
strange behavior so things had been changed in places from what one
would think the simplest. Various print statements placed at places to
check values for debug.
It is not for a contest or such.
There are already several fine tools for timing clocks. The problem with
all of them is that they all require some method of connecting to the
clock.
Optical interrupters need to be closely spaced and are effected by ambient
lighting. They often are not compatible with the size and shape of the
pendulum.
Acoustic pickups are also problematic in that clocks make a lot
of different sound and require special filters and careful level adjustments.
It occurred to me that a strobe could be made to work if it had some
added features. The strobe has the advantage that it doesn’t need to
be connected to the clock.
One would set the phase of the strobe to
match the clock and let it run for some time, watching the drift.
One would then re-center with the phase and readout how much
time was gained or lost for that amount of phase change.
One needed an accurate strobe rate. This is the done with the math and the
DS3231 reference to the 1 second pulse to correct the resonator used to
time the processor.
It needed a way of adjusting the phase of the strobe to match the pendulum
so that one could set the strobe at a location where is was most sensitive to
a change in speed ( the center of the swing ).
I do this with a scaled value from a 10K pot.
One needs to be able to make a change of the clocks adjustment and know
how much it effected the rate ( coding in progress ). It has the math, I just need
to add the display code. I want the display to say FAST or SLOW. That is the
reason for separating the sign and your comment about the abs() function.
The part I’m planning to change is how one sets the evenness of the beat.
I’d thought to use the two colors of LED to set the beat. On experimenting,
I realized that the connection between blink and sound wasn’t going to work.
If the blink happened anywhere near the same time as the sound, the mind
seems to just connect the two together, as though they both happen at the
same time. For this I expect to add a speaker to make the tic and toc sound
and remove one light.
I have yet to add the code to set the BPH rate, for different clocks, as things
are still being worked on.
The main function is working fine except the strange delay behavior.
Dwight