Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 6:c2040b4cf589, committed 2013-08-21
- Comitter:
- vsluiter
- Date:
- Wed Aug 21 20:47:16 2013 +0000
- Parent:
- 5:d2e819018807
- Child:
- 7:e605dbca7330
- Commit message:
- First interaction!
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- 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)