From 523f047b1b3c42b0aa40305291ca5d29a1b543f5 Mon Sep 17 00:00:00 2001 From: Vasil Zlatanov Date: Sat, 6 May 2017 19:10:56 +0100 Subject: Seperate counter into propper code and head file --- src/counter.h | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'src/counter.h') diff --git a/src/counter.h b/src/counter.h index e47475e..cc3e2f4 100644 --- a/src/counter.h +++ b/src/counter.h @@ -1,24 +1,19 @@ -#include "mbed.h" +#ifndef COUNTER_H +#define COUNTER_H -class Counter { -public: - Counter(PinName pin) : _interrupt(pin) { // create the InterruptIn on the pin specified to Counter - _interrupt.rise(this, &Counter::increment); // attach increment function of this counter instance - } - - void increment() { - _count++; - } - - int read() { - return _count; - } +#include "mbed.h" - void write(int new_count) { - _count = new_count; - } - +class Counter +{ private: InterruptIn _interrupt; volatile int _count; + +public: + Counter(PinName pin); + void increment(); + int read(); + void write(int new_count); }; + +#endif -- cgit v1.2.3-54-g00ecf