This class carries out software debouncing of Digitial in, and provides some method to look at details such as how many debounced rising and falling there have been, and how long the input has been in its current stable state.

Dependencies:   mbed

Committer:
chris
Date:
Fri Nov 27 16:05:32 2009 +0000
Revision:
0:672241227e0d

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 0:672241227e0d 1 #include "mbed.h"
chris 0:672241227e0d 2
chris 0:672241227e0d 3 class DebouncedIn {
chris 0:672241227e0d 4 public:
chris 0:672241227e0d 5 DebouncedIn(PinName in);
chris 0:672241227e0d 6
chris 0:672241227e0d 7 int read (void);
chris 0:672241227e0d 8 operator int();
chris 0:672241227e0d 9
chris 0:672241227e0d 10 int rising(void);
chris 0:672241227e0d 11 int falling(void);
chris 0:672241227e0d 12 int steady(void);
chris 0:672241227e0d 13
chris 0:672241227e0d 14 private :
chris 0:672241227e0d 15 // objects
chris 0:672241227e0d 16 DigitalIn _in;
chris 0:672241227e0d 17 Ticker _ticker;
chris 0:672241227e0d 18
chris 0:672241227e0d 19 // function to take a sample, and update flags
chris 0:672241227e0d 20 void _sample(void);
chris 0:672241227e0d 21
chris 0:672241227e0d 22 // counters and flags
chris 0:672241227e0d 23 int _samples;
chris 0:672241227e0d 24 int _output;
chris 0:672241227e0d 25 int _output_last;
chris 0:672241227e0d 26 int _rising_flag;
chris 0:672241227e0d 27 int _falling_flag;
chris 0:672241227e0d 28 int _state_counter;
chris 0:672241227e0d 29
chris 0:672241227e0d 30 };
chris 0:672241227e0d 31