jhanarato / functimer

A Functional Timer (Arduino project)
GNU General Public License v3.0
0 stars 0 forks source link

Debug & fix session timer. #23

Closed jhanarato closed 8 years ago

jhanarato commented 8 years ago

I'm now working on the session timing code. I have a new branch (fix_timing) and have stripped the sketch ino file down to the following:

#include "buzzer.h"
#include "timer.h"

Buzzer buzzer = Buzzer(300);
Timer sessionTimer;

void setup()
{
    sessionTimer.setDuration(30000);
    sessionTimer.start();
}

void loop()
{
    sessionTimer.update();

    if(sessionTimer.isComplete())
    {
        buzzer.buzz();
        sessionTimer.stop();
    }
}

A first run of this code yields a beep at 45 seconds.

jhanarato commented 8 years ago

I have rewritten the Timer implementation, using an enum type instead of having two booleans hold state. I then discovered that I was checking equality rather than making an assignment (== versus =) in Timer::update(). There is not much else that could go wrong here, so time for more tests.

jhanarato commented 8 years ago

Ok, a very basic timer test:

  1. Switches at off-off-on.
  2. LONG_TIME = 20000, SHORT_TIME = 5000.
  3. Power on.
  4. Turn switch 1 on.
  5. Beep once, after 5 seconds.
jhanarato commented 8 years ago

Above test works fine. Same again, with switches at off-on-on. Should beep at 20 seconds.

Success!

jhanarato commented 8 years ago

Looks like everything works, with issue #24 the only remaining problem.