pachas

Dependencies:   mbed QEI FastPWM

Revision:
0:9d0b9785d3d6
Child:
3:45299e7882b9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/buttons.h	Sat Apr 11 22:53:05 2020 +0000
@@ -0,0 +1,40 @@
+#ifndef BUTTONS_H_
+#define BUTTONS_H_
+
+#include "mbed.h"
+#include "stdint.h"
+#include "project_defines.h" 
+
+/* Object declaration */
+extern BusIn  buttons;
+
+/* Global variable declaration */
+extern volatile uint8_t button_state; // debounced button state (bit == 1: button pressed)
+extern volatile uint8_t button_press; // button press detect
+
+/* Functions declaration */
+void Buttons_Initialize(void);
+uint8_t Get_Button_Press(uint8_t button_mask);
+
+
+
+/***********************************************************************
+   buttonDebounce: Check if a button has changed and keeps its new value 
+   (HIGH or LOW) for 03 periods of time.
+************************************************************************/
+
+static inline void Button_Debounce(void){
+    static unsigned char ct0, ct1;
+    unsigned char k = 0;
+
+    k = button_state ^ (~buttons);           // button changed ?
+    ct1 = (ct0 ^ ct1) & k;                   // reset or count ct1
+    ct0 = (~ct0) & k;                        // reset or count ct0
+    k &= ct0 & ct1;                          // count until roll over
+    button_state ^= k;                       // then toggle debounced state
+    button_press |= button_state & k;        // 0->1: button press detect
+
+}
+
+
+#endif /* BUTTONS_H_ */
\ No newline at end of file