1D-Pong game based on a LED strip with 150 LPD6803-controlled pixels. Game keeps score for 'best-of-21' game. Written for KL25Z

Dependencies:   MODSERIAL mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GameButton.cpp Source File

GameButton.cpp

00001 #include "GameButton.h"
00002 
00003 GameButton::GameButton(PinName pin, float time=0.5)
00004 {
00005     pushflag = false;
00006     intpin = new InterruptIn(pin);
00007     (*intpin).mode(PullUp);
00008     (*intpin).fall(this, &GameButton::PushHandler);
00009     m_time = time;
00010     m_timeoutactive = false;
00011     inpin = pin;
00012     //timeout = new Timeout(m_time);
00013 }
00014 
00015 void GameButton::PushHandler(void)
00016 {
00017     DigitalIn input(inpin);
00018     wait_ms(5);
00019     if(!input)
00020     {
00021         pushflag = true;
00022         m_timeoutactive = true;
00023         timeout.attach(this, &GameButton::TimeOutHandler, m_time);
00024         pushhandlercallback();
00025     }
00026 }
00027 
00028 void GameButton::TimeOutHandler(void)
00029 {
00030     m_timeoutactive = false;
00031 }
00032 
00033 bool GameButton::getTimeoutActive(void)
00034 {
00035     return m_timeoutactive;
00036 }