1D-Pong game based on a LED strip with 150 LPD6803-controlled pixels. Game keeps score for 'best-of-21' game. Written for KL25Z
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
diff -r 3144a392690b -r 448ee3b0b481 GameButton.cpp --- 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)
diff -r 3144a392690b -r 448ee3b0b481 GameButton.h --- 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; };
diff -r 3144a392690b -r 448ee3b0b481 main.cpp --- 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);