power rangers
/
MavisBeacon
mavis beacon
Revision 1:c169262246ee, committed 2014-03-19
- Comitter:
- jlaqua
- Date:
- Wed Mar 19 15:18:55 2014 +0000
- Parent:
- 0:a53216950e40
- Commit message:
- we type like its our job
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r a53216950e40 -r c169262246ee main.cpp --- a/main.cpp Tue Mar 04 03:58:55 2014 +0000 +++ b/main.cpp Wed Mar 19 15:18:55 2014 +0000 @@ -2,20 +2,80 @@ #include "C12832.h" C12832 lcd(p5, p7, p6, p8, p11); -DigitalIn play(p14); +Timeout ender; +Timer timer; +Serial term(USBTX, USBRX); +InterruptIn iFrackedUp(p14); + +char sents[][65] = {"Jackdaws love my big sphinx of quartz. ", + "The quick brown fox jumped over the lazy dog. ", + "Cwm fjordbank glyphs vext quiz. ", + "Pack my box with five dozen liquor jugs. ", + "A quick movement of the enemy will jeopardize six gunboats. ", + "The five boxing wizards jump quickly. ", + "Crazy Fredericka bought many very exquisite opal jewels. ", + "Amazingly few discotheques provide jukeboxes. ", + "Sphinx of black quartz, judge my vow! ", + "Brawny gods just flocked up to quiz and vex him. "}; -char sents[][60] = {"Jackdaws love my big sphinx of quartz.", - "The quick brown fox jumped over the lazy dog.", - "Cwm fjordbank glyphs vext quiz.", - "Pack my box with five dozen liquor jugs.", - "A quick movement of the enemy will jeopardize six gunboats.", - "The five boxing wizards jump quickly.", - "Crazy Fredericka bought many very exquisite opal jewels.", - "Amazingly few discotheques provide jukeboxes.", - "Sphinx of black quartz, judge my vow!", - "Brawny gods just flocked up to quiz and vex him."}; +int wordsTyped; +int lettersTotal; +int lettersCorrect; +int reset = true; + +void game() { + lcd.cls(); + lcd.printf("WPM: %.2f\n", (float)wordsTyped); + lcd.printf("Accuracy: %.2f%%\n", (float)(lettersCorrect)/lettersTotal*100); + ender.detach(); +} + +void frack() { + lcd.cls(); + float wpm = 60 * wordsTyped / timer.read(); + lcd.printf("WPM: %.2f\n", wpm); + lcd.printf("Accuracy: %.2f%%\n", (float)(lettersCorrect)/lettersTotal*100); +} int main() { - + timer.start(); + if (reset) { + lettersTotal = 0; + lettersCorrect = 0; + wordsTyped = 1; + ender.attach(&game, 60); + iFrackedUp.rise(&frack); + reset = false; + timer.reset(); + char prev = ' '; + char let = ' '; + while (1) + { + for (int i = 0; i < sizeof(sents)/sizeof(*sents); i++) { + lcd.cls(); + lcd.locate(0,0); + lcd.printf("%s\n", sents[i]); + for (int j = 0; j < sizeof(sents[i])/sizeof(*(sents[i])); j++) { + if (sents[i][j] == '\0') + break; + prev = let; + let = term.getc(); +// if (let == 0x08) +// { +// j -= 2; +// if (j < 0) j = 0; +// } +// else + { + lettersTotal++; + if (sents[i][j] == let) + lettersCorrect++; + } + if (' ' == let && ' ' != prev) + wordsTyped++; + } + } + } + } }