The world's greatest etch a sketch
Dependencies: mbed C12832 MMA7660
Diff: main.cpp
- Revision:
- 3:c385027fcc0b
- Parent:
- 2:aed0788e8f96
- Child:
- 4:be4ba8a111ce
--- a/main.cpp Thu Feb 20 02:01:06 2014 +0000 +++ b/main.cpp Tue Feb 25 20:52:24 2014 +0000 @@ -25,9 +25,12 @@ int ballY; int ballState = START; + void pong(void) { while(1) { + DigitalIn up(p15); + DigitalIn down(p12); switch(badGuyState) { case DOWN: badGuy++; @@ -41,12 +44,15 @@ break; } - goodGuy -= up; - goodGuy += down; + if (up) + goodGuy--; + if (down) + goodGuy++; + if (goodGuy < 0) goodGuy = 0; - if (goodGuy + 5 > lcd.width()-1) - goodGuy = lcd.width()-6; + if (goodGuy + 5 > lcd.height()-1) + goodGuy = lcd.height()-6; switch(ballState) { case LEFTUP: @@ -112,20 +118,21 @@ lcd.line(0, badGuy, 0, badGuy+5, 1); lcd.line(lcd.width()-1, goodGuy, lcd.width()-1, goodGuy+5, 1); lcd.copy_to_lcd(); - wait(0.02); + wait(0.03); } } void etchASketch() { int counter = 0; + acc.setSampleRate(120); while(1) { int x = (int)((1-potX) * lcd.width()); int y = (int)((1-potY) * lcd.height()); lcd.pixel(x, y, 1); lcd.copy_to_lcd(); if (counter > 100) { - if ((acc.x() > 1.3) || (acc.y() > 1.3)) + if (acc.x() > 1.3) lcd.cls(); counter = 0; } @@ -158,6 +165,4 @@ lcd.fillcircle(12,13+choice*8,2,1); lcd.copy_to_lcd(); } - //etchASketch(); - //pong(); }