1D-Pong game based on a LED strip with 150 LPD6803-controlled pixels. Game keeps score for 'best-of-21' game. Written for KL25Z
Diff: main.cpp
- Revision:
- 6:c2040b4cf589
- Parent:
- 5:d2e819018807
- Child:
- 7:e605dbca7330
--- a/main.cpp Wed Aug 21 20:21:43 2013 +0000 +++ b/main.cpp Wed Aug 21 20:47:16 2013 +0000 @@ -102,12 +102,30 @@ } Paddle paddle; +bool leftpushed = false, rightpushed = false; +void left_pushed(void) +{ + if(paddle.direction == 1) + leftpushed = true; +} + +void right_pushed(void) +{ + if(paddle.direction != 1) + rightpushed = true; +} int main() { Ticker updater; Ticker demopaddlepos; + InterruptIn buttonleft(PTD5); + InterruptIn buttonright(PTD0); uint8_t ledcounter; + buttonleft.mode(PullUp); + buttonright.mode(PullUp); + buttonleft.fall(left_pushed); + buttonright.fall(right_pushed); updater.attach(UpdateLEDstrip, .02); demopaddlepos.attach(UpdateDemoPaddle, .03); ledstrip.format(8,0); //15 bits, mode '0' @@ -124,9 +142,23 @@ //Score(3,2); //WinLoose(2.5, LEFT); if(paddle.direction == 1) + { paddle.position++; + if(leftpushed) + { + leftpushed = false; + paddle.direction = 0; + } + } else + { paddle.position--; + if(rightpushed) + { + rightpushed = false; + paddle.direction = 1; + } + } if(paddle.position == NUMBER_OF_PIXELS) paddle.direction = 0; if(paddle.position == -7)