Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: UserButton.h
- Revision:
- 0:94d6bf511846
- Child:
- 1:d5f5481d7eaf
- Child:
- 2:7a268df54696
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/UserButton.h Fri Jul 12 07:35:10 2019 +0000
@@ -0,0 +1,47 @@
+InterruptIn mybutton(USER_BUTTON);
+
+Timeout FrameTimeout;
+Timeout BounceTimeout;
+
+uint8_t Debounce=0;
+uint8_t cnt=0,*pind_cnt;
+uint8_t *pmode=0;
+
+
+//------------------
+void FrameTimeout_isr()
+{
+ *pmode=cnt;
+ cnt=0;
+}
+
+//---------------------
+void BounceTimeout_isr()
+{
+ Debounce=0;
+
+}
+
+//------------
+void pressed()
+{
+ if(Debounce==0){
+ Debounce=1;
+ cnt++;
+ *pind_cnt=cnt;
+ FrameTimeout.detach();
+ FrameTimeout.attach(FrameTimeout_isr,1.0);
+ BounceTimeout.attach(BounceTimeout_isr,0.2);
+ }
+}
+
+//-----------------------------------
+void ButtonIni(uint8_t *pind,uint8_t *pm)
+{
+ pmode=pm;
+ pind_cnt=pind;
+ mybutton.fall(&pressed);
+ }
+
+
+