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:
- 1:7a2ec350cdf5
- Parent:
- 0:cde34c55fa20
- Child:
- 2:d2f8772a8db5
--- a/main.cpp Wed Aug 21 16:52:51 2013 +0000 +++ b/main.cpp Wed Aug 21 17:14:08 2013 +0000 @@ -5,26 +5,12 @@ 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); uint16_t totalstrip[NUMBER_OF_PIXELS]; volatile int8_t paddlestart= 0; SPI ledstrip(PTD2,NC,PTD1); -void UpdatePaddle(void) -{ - static uint8_t direction = 1; - if(direction) { - paddlestart++; - } else { - paddlestart--; - } - - if(paddlestart > (NUMBER_OF_PIXELS - PADDLE_LENGTH)) - direction = 0; - if(paddlestart < 0) - direction = 1; - -} void UpdateLEDstrip(void) { @@ -57,11 +43,41 @@ write_led(&totalstrip[ledcounter], 0,0,0); } while(1) { - PaddleDemo(5,255,10,100); + PaddleDemo(2,255,10,100); + WinLoose(3, true); Randomblinks(5, true); + WinLoose(3, false); } } +void WinLoose(float seconds, bool side) +{ + uint8_t ledcounter; + Timer timer; + timer.start(); + while( timer.read() < seconds) + { + uint8_t redvalue = 255-(255.0*(timer.read()/(seconds/2))); + for(ledcounter = 0; ledcounter < NUMBER_OF_PIXELS; ledcounter++) + { + if(ledcounter < NUMBER_OF_PIXELS / 2) + { + if(side) + write_led(&totalstrip[ledcounter], redvalue,0,0); + else + write_led(&totalstrip[ledcounter], 0,255,0); + } + else + { + if(side) + write_led(&totalstrip[ledcounter], 0,255,0); + else + write_led(&totalstrip[ledcounter], redvalue ,0,0); + + } + } + } +} void PaddleDemo(float seconds, uint8_t red, uint8_t green, uint8_t blue) { uint8_t ledcounter; @@ -103,6 +119,21 @@ } } +void UpdatePaddle(void) +{ + static uint8_t direction = 1; + if(direction) { + paddlestart++; + } else { + paddlestart--; + } + + if(paddlestart > (NUMBER_OF_PIXELS - PADDLE_LENGTH)) + direction = 0; + if(paddlestart < 0) + direction = 1; +} + //DigitalOut myled(LED1); //int main() {