AirsoftTimer software based on mbed
Dependencies: mbed TextLCD keypad
games/ShowBuzzer.cpp
- Committer:
- sillevl
- Date:
- 2014-12-31
- Revision:
- 11:50572814f73e
- Child:
- 12:22e9ef610ea2
File content as of revision 11:50572814f73e:
#include "ShowBuzzer.h" static const char* NAME = "ShowBuzzer"; ShowBuzzer::ShowBuzzer(Board* board) : Game(board){ board->keyboard->attach(this,&ShowBuzzer::keyPressed); board->keyboard->start(); board->leds->off(Leds::ALL); } void ShowBuzzer::run(){ board->lcd->printf("ShowBuzzer"); newRound(); while(true){ //wait for button press Team team = waitForButtonPress(); //show leds setLeds(team); //show display setDisplay(team); //play sound playSound(); //wait for 3 seconds wait_ms(5000); //start new round newRound(); // don't return from this function yet (only if the game ends); } } void ShowBuzzer::newRound(){ board->buzzer->playNote(200,50); board->leds->off(Leds::ALL); board->lcd->cls(); board->lcd->printf("*** WAITING ***"); } ShowBuzzer::Team ShowBuzzer::waitForButtonPress(){ Team team; while(true){ if(board->button->read() == 0){ team = TEAM_B; break; } if(board->key->read() == 0){ team = TEAM_A; break; } } return team; } void ShowBuzzer::setLeds(Team team){ switch(team){ case TEAM_A: board->leds->on(Leds::LEFT); break; case TEAM_B: board->leds->on(Leds::RIGHT); break; default: break; } } void ShowBuzzer::setDisplay(Team team){ board->lcd->locate(0,0); board->lcd->cls(); switch(team){ case TEAM_A: board->lcd->printf("Team A"); break; case TEAM_B: board->lcd->printf("Team B"); break; default: break; } } void ShowBuzzer::playSound(){ board->buzzer->playNote(698, 50); board->buzzer->playNote(783, 50); board->buzzer->playNote(880, 50); board->buzzer->playNote(987, 50); board->buzzer->playNote(1108, 50); board->buzzer->playNote(1244, 50); board->buzzer->playNote(1396, 50); board->buzzer->playNote(1567, 50); board->buzzer->playNote(1760, 50); board->buzzer->playNote(1975, 50); } void ShowBuzzer::playCorrect(){ board->buzzer->playNote(2093, 100); board->buzzer->playNote(2637, 100); board->buzzer->playNote(3165, 100); board->buzzer->playNote(3951, 100); } void ShowBuzzer::playWrong(){ board->buzzer->playNote(440, 1000); } uint32_t ShowBuzzer::keyPressed(uint32_t key){ if(key == 11){ playCorrect();} if(key == 9){ playWrong();} return 0; }