mavis beacon

Dependencies:   C12832 mbed

Committer:
jlaqua
Date:
Wed Mar 19 15:18:55 2014 +0000
Revision:
1:c169262246ee
Parent:
0:a53216950e40
we type like its our job

Who changed what in which revision?

UserRevisionLine numberNew contents of line
farzeen 0:a53216950e40 1 #include "mbed.h"
farzeen 0:a53216950e40 2 #include "C12832.h"
farzeen 0:a53216950e40 3
farzeen 0:a53216950e40 4 C12832 lcd(p5, p7, p6, p8, p11);
jlaqua 1:c169262246ee 5 Timeout ender;
jlaqua 1:c169262246ee 6 Timer timer;
jlaqua 1:c169262246ee 7 Serial term(USBTX, USBRX);
jlaqua 1:c169262246ee 8 InterruptIn iFrackedUp(p14);
jlaqua 1:c169262246ee 9
jlaqua 1:c169262246ee 10 char sents[][65] = {"Jackdaws love my big sphinx of quartz. ",
jlaqua 1:c169262246ee 11 "The quick brown fox jumped over the lazy dog. ",
jlaqua 1:c169262246ee 12 "Cwm fjordbank glyphs vext quiz. ",
jlaqua 1:c169262246ee 13 "Pack my box with five dozen liquor jugs. ",
jlaqua 1:c169262246ee 14 "A quick movement of the enemy will jeopardize six gunboats. ",
jlaqua 1:c169262246ee 15 "The five boxing wizards jump quickly. ",
jlaqua 1:c169262246ee 16 "Crazy Fredericka bought many very exquisite opal jewels. ",
jlaqua 1:c169262246ee 17 "Amazingly few discotheques provide jukeboxes. ",
jlaqua 1:c169262246ee 18 "Sphinx of black quartz, judge my vow! ",
jlaqua 1:c169262246ee 19 "Brawny gods just flocked up to quiz and vex him. "};
farzeen 0:a53216950e40 20
jlaqua 1:c169262246ee 21 int wordsTyped;
jlaqua 1:c169262246ee 22 int lettersTotal;
jlaqua 1:c169262246ee 23 int lettersCorrect;
jlaqua 1:c169262246ee 24 int reset = true;
jlaqua 1:c169262246ee 25
jlaqua 1:c169262246ee 26 void game() {
jlaqua 1:c169262246ee 27 lcd.cls();
jlaqua 1:c169262246ee 28 lcd.printf("WPM: %.2f\n", (float)wordsTyped);
jlaqua 1:c169262246ee 29 lcd.printf("Accuracy: %.2f%%\n", (float)(lettersCorrect)/lettersTotal*100);
jlaqua 1:c169262246ee 30 ender.detach();
jlaqua 1:c169262246ee 31 }
jlaqua 1:c169262246ee 32
jlaqua 1:c169262246ee 33 void frack() {
jlaqua 1:c169262246ee 34 lcd.cls();
jlaqua 1:c169262246ee 35 float wpm = 60 * wordsTyped / timer.read();
jlaqua 1:c169262246ee 36 lcd.printf("WPM: %.2f\n", wpm);
jlaqua 1:c169262246ee 37 lcd.printf("Accuracy: %.2f%%\n", (float)(lettersCorrect)/lettersTotal*100);
jlaqua 1:c169262246ee 38 }
farzeen 0:a53216950e40 39
farzeen 0:a53216950e40 40 int main()
farzeen 0:a53216950e40 41 {
jlaqua 1:c169262246ee 42 timer.start();
jlaqua 1:c169262246ee 43 if (reset) {
jlaqua 1:c169262246ee 44 lettersTotal = 0;
jlaqua 1:c169262246ee 45 lettersCorrect = 0;
jlaqua 1:c169262246ee 46 wordsTyped = 1;
jlaqua 1:c169262246ee 47 ender.attach(&game, 60);
jlaqua 1:c169262246ee 48 iFrackedUp.rise(&frack);
jlaqua 1:c169262246ee 49 reset = false;
jlaqua 1:c169262246ee 50 timer.reset();
jlaqua 1:c169262246ee 51 char prev = ' ';
jlaqua 1:c169262246ee 52 char let = ' ';
jlaqua 1:c169262246ee 53 while (1)
jlaqua 1:c169262246ee 54 {
jlaqua 1:c169262246ee 55 for (int i = 0; i < sizeof(sents)/sizeof(*sents); i++) {
jlaqua 1:c169262246ee 56 lcd.cls();
jlaqua 1:c169262246ee 57 lcd.locate(0,0);
jlaqua 1:c169262246ee 58 lcd.printf("%s\n", sents[i]);
jlaqua 1:c169262246ee 59 for (int j = 0; j < sizeof(sents[i])/sizeof(*(sents[i])); j++) {
jlaqua 1:c169262246ee 60 if (sents[i][j] == '\0')
jlaqua 1:c169262246ee 61 break;
jlaqua 1:c169262246ee 62 prev = let;
jlaqua 1:c169262246ee 63 let = term.getc();
jlaqua 1:c169262246ee 64 // if (let == 0x08)
jlaqua 1:c169262246ee 65 // {
jlaqua 1:c169262246ee 66 // j -= 2;
jlaqua 1:c169262246ee 67 // if (j < 0) j = 0;
jlaqua 1:c169262246ee 68 // }
jlaqua 1:c169262246ee 69 // else
jlaqua 1:c169262246ee 70 {
jlaqua 1:c169262246ee 71 lettersTotal++;
jlaqua 1:c169262246ee 72 if (sents[i][j] == let)
jlaqua 1:c169262246ee 73 lettersCorrect++;
jlaqua 1:c169262246ee 74 }
jlaqua 1:c169262246ee 75 if (' ' == let && ' ' != prev)
jlaqua 1:c169262246ee 76 wordsTyped++;
jlaqua 1:c169262246ee 77 }
jlaqua 1:c169262246ee 78 }
jlaqua 1:c169262246ee 79 }
jlaqua 1:c169262246ee 80 }
farzeen 0:a53216950e40 81 }