/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock
16 by edam
finished first revision of propeller-clock code (can display clock and test); added Bounce library
1
2
/*
3
 *      This program is free software; you can redistribute it and/or modify
4
 *      it under the terms of the GNU General Public License as published by
5
 *      the Free Software Foundation; either version 2 of the License, or
6
 *      (at your option) any later version.
7
 *      
8
 *      This program is distributed in the hope that it will be useful,
9
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 *      GNU General Public License for more details.
12
 *      
13
 *      You should have received a copy of the GNU General Public License
14
 *      along with this program; if not, write to the Free Software
15
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16
 *      MA 02110-1301, USA.
17
 */
18
19
20
21
/*  * * * * * * * * * * * * * * * * * * * * * * * * * * * 
22
 Main code by Thomas O Fredericks
23
 Rebounce and duration functions contributed by Eric Lowry
24
 Write function contributed by Jim Schimpf
25
 risingEdge and fallingEdge contributed by Tom Harkaway
26
* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
27
28
#ifndef Bounce_h
29
#define Bounce_h
30
31
#include <inttypes.h>
32
33
class Bounce
34
{
35
36
public:
37
	// Initialize
38
  Bounce(uint8_t pin, unsigned long interval_millis ); 
39
	// Sets the debounce interval
40
  void interval(unsigned long interval_millis); 
41
	// Updates the pin
42
	// Returns 1 if the state changed
43
	// Returns 0 if the state did not change
44
  int update(); 
45
	// Forces the pin to signal a change (through update()) in X milliseconds 
46
	// even if the state does not actually change
47
	// Example: press and hold a button and have it repeat every X milliseconds
48
  void rebounce(unsigned long interval); 
49
	// Returns the updated pin state
50
  int read();
51
	// Sets the stored pin state
52
  void write(int new_state);
53
    // Returns the number of milliseconds the pin has been in the current state
54
  unsigned long duration();
42 by edam
lengthened button debounce time and turned on the pull-up resistor (oops!)
55
    // The risingEdge method is true for one scan after the de-bounced
56
    // input goes from off-to-on.
57
  bool risingEdge();
58
    // The fallingEdge method it true for one scan after the
59
    // de-bounced input goes from on-to-off.
60
  bool fallingEdge();
16 by edam
finished first revision of propeller-clock code (can display clock and test); added Bounce library
61
  
62
protected:
63
  int debounce();
64
  unsigned long  previous_millis, interval_millis, rebounce_millis;
65
  uint8_t state;
66
  uint8_t pin;
67
  uint8_t stateChanged;
68
};
69
70
#endif
71
72