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.
Revision 26:448ee3b0b481, committed 2013-09-07
- Comitter:
- vsluiter
- Date:
- Sat Sep 07 10:59:26 2013 +0000
- Parent:
- 25:3144a392690b
- Commit message:
- Adapted button with software debounce, made left button a bit easier (hitting sooner is OK)
Changed in this revision
--- a/GameButton.cpp Tue Sep 03 22:30:16 2013 +0000
+++ b/GameButton.cpp Sat Sep 07 10:59:26 2013 +0000
@@ -8,15 +8,21 @@
(*intpin).fall(this, &GameButton::PushHandler);
m_time = time;
m_timeoutactive = false;
+ inpin = pin;
//timeout = new Timeout(m_time);
}
void GameButton::PushHandler(void)
{
- pushflag = true;
- m_timeoutactive = true;
- timeout.attach(this, &GameButton::TimeOutHandler, m_time);
- pushhandlercallback();
+ DigitalIn input(inpin);
+ wait_ms(5);
+ if(!input)
+ {
+ pushflag = true;
+ m_timeoutactive = true;
+ timeout.attach(this, &GameButton::TimeOutHandler, m_time);
+ pushhandlercallback();
+ }
}
void GameButton::TimeOutHandler(void)
--- a/GameButton.h Tue Sep 03 22:30:16 2013 +0000
+++ b/GameButton.h Sat Sep 07 10:59:26 2013 +0000
@@ -18,6 +18,8 @@
bool m_timeoutactive;
void TimeOutHandler(void);
virtual void PushHandler(void);
+ private:
+ PinName inpin;
};
--- a/main.cpp Tue Sep 03 22:30:16 2013 +0000
+++ b/main.cpp Sat Sep 07 10:59:26 2013 +0000
@@ -5,7 +5,7 @@
#define NUMBER_OF_PIXELS 50
#define PADDLE_LENGTH 5
#define START_SPEED 19
-#define SPEED_FACTOR 6
+#define SPEED_FACTOR 7
#define LEFT false
#define RIGHT true
@@ -134,7 +134,7 @@
//printf("\n\rleft pushed");
pc.printf("L\n\r");
buttonleft.pushflag = false;
- if(buttonleft.paddlepos <= 0 )
+ if(buttonleft.paddlepos <= 1 )
{
paddle.direction = 1;
paddle.setSpeed(START_SPEED+(-buttonleft.paddlepos)*SPEED_FACTOR);