Simple sugar dozer emulator in coffee machines.
Dependencies: mbed
Diff: EventCounter.cpp
- Revision:
- 0:23fb6d1ad75c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EventCounter.cpp Thu Jan 29 11:09:25 2015 +0000 @@ -0,0 +1,26 @@ +#include "EventCounter.h" + +EventCounter::EventCounter(PinName pin, int initialCount) : input(pin) { + if (initialCount >= 0 && initialCount < 5) + count = initialCount; + else + count = 0; + input.rise(this, &EventCounter::event); + debounce.start(); +} + +int EventCounter::getCount() { + return count; +} + +void EventCounter::reset() { + count = 0; +} + +void EventCounter::event() { + if (debounce.read_ms() > 200) { + ++count; + count %= 5; + debounce.reset(); + } +} \ No newline at end of file