![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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:
- 2:d2f8772a8db5
- Parent:
- 1:7a2ec350cdf5
- Child:
- 3:a2b58da5c03b
--- a/main.cpp Wed Aug 21 17:14:08 2013 +0000 +++ b/main.cpp Wed Aug 21 18:22:29 2013 +0000 @@ -2,11 +2,13 @@ #define NUMBER_OF_PIXELS 50 #define PADDLE_LENGTH 5 - +#define LEFT false +#define RIGHT true void Randomblinks(float seconds, bool colored = false); void PaddleDemo(float seconds, uint8_t red, uint8_t green, uint8_t blue); void WinLoose(float seconds, bool side); void UpdatePaddle(void); +void Score(uint8_t left, uint8_t right); uint16_t totalstrip[NUMBER_OF_PIXELS]; volatile int8_t paddlestart= 0; SPI ledstrip(PTD2,NC,PTD1); @@ -43,13 +45,48 @@ write_led(&totalstrip[ledcounter], 0,0,0); } while(1) { - PaddleDemo(2,255,10,100); - WinLoose(3, true); - Randomblinks(5, true); - WinLoose(3, false); + //PaddleDemo(2,255,10,100); + Score(0,0); + Score(1,0); + Score(0,1); + Score(3,2); + WinLoose(2.5, LEFT); + Score(3,4); + WinLoose(1.5, RIGHT); + //Randomblinks(5, true); + //WinLoose(3, false); } } +void Score(uint8_t left, uint8_t right) +{ + uint8_t maxscore; + int8_t ledcounter; + uint8_t scorecounter; + left>right?maxscore=left:maxscore=right; + for(scorecounter = 0 ; scorecounter <= maxscore ; scorecounter++) + { + uint8_t templeft,tempright; + templeft = left>scorecounter?scorecounter:left; + tempright = right>scorecounter?scorecounter:right; + uint8_t sidecounter; + for(ledcounter = 0; ledcounter < NUMBER_OF_PIXELS; ledcounter++) + { + write_led(&totalstrip[ledcounter], 0, 0 ,0); + } + for(sidecounter = 0 ; sidecounter < templeft; sidecounter++) + { + write_led(&totalstrip[sidecounter*2],255,255,0); + } + for(sidecounter = 0 ; sidecounter < tempright ; sidecounter++) + { + write_led(&totalstrip[(NUMBER_OF_PIXELS-1)-(sidecounter*2)],255,255,0); + } + wait(0.5); + } + wait(1); +} + void WinLoose(float seconds, bool side) { uint8_t ledcounter; @@ -134,6 +171,7 @@ direction = 1; } + //DigitalOut myled(LED1); //int main() {