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.
lib/Options/Options.cpp
- Committer:
- Kern_EL17KJTF
- Date:
- 2019-05-09
- Revision:
- 23:ecb74e52163d
- Parent:
- 11:b288d01533cc
File content as of revision 23:ecb74e52163d:
/*
ELEC2645 Project
Options.cpp
Class file for Options in Donkey Kong game.
*/
#include "Options.h"
// Constructor - Doesn't require any setup.
Options::Options()
{
}
// Deconstructor - Doesn't require any setup.
Options::~Options()
{
}
// External variables to be used inside and out of the class.
float opt_brightness = 0.5;
float opt_contrast = 0.396;
int opt_volume = 1;
// Runs and controls all the options functions.
void Options::options_run(Gamepad &pad, N5110 &lcd) {
wait_ms(250);
while (pad.check_event(Gamepad::BACK_PRESSED) == false) { // Continues to show this screen until BACK button pressed.
//printf("Options State");
lcd.clear();
lcd.printString("Options",21,0);
options_brightness(pad, lcd); // Calls brightness function within class.
options_contrast(pad, lcd); // Calls contrast function within class.
options_volume(pad, lcd); // Calls volume function within class.
lcd.refresh(); // Reloads screen on every cycle, controlled by fps. Default set to 24.
wait_ms(1.0f/24);
}
}
// Toggles the backlight on LCD screen, ON/OFF based on button inputs.
void Options::options_brightness(Gamepad &pad, N5110 &lcd) {
if (pad.check_event(Gamepad::B_PRESSED) == true) { // If B is pressed, will turn off backlight.
opt_brightness = 0;
}
if (pad.check_event(Gamepad::A_PRESSED) == true) { // If A is pressed, will turn on backlight.
opt_brightness = 0.5;
}
lcd.setBrightness(opt_brightness);
lcd.printString("A/B = BackLite",0,2);
}
// Controls the LCD screen contrast based on gamepad potentiometer value.
void Options::options_contrast(Gamepad &pad, N5110 &lcd) {
opt_contrast = pad.read_pot(); // Gets potentiometer value from gamepad and assigns it to a value.
lcd.setContrast(opt_contrast); // Uses set value to change actual LCD contrast.
lcd.printString("Pot = Contrast",0,3);
printf("Contrast = %f", opt_contrast);
}
// Toggles the volume for the game, ON/OFF based on button inputs.
void Options::options_volume(Gamepad &pad, N5110 &lcd) {
if (pad.check_event(Gamepad::Y_PRESSED) == true) { // If Y is pressed, will disable volume.
opt_volume = 0;
}
if (pad.check_event(Gamepad::X_PRESSED) == true) { // If X is press, will enable volume.
opt_volume = 1;
pad.tone(2400, 0.2); // Plays a set of beeps to confirm the volume is on.
wait_ms(200);
pad.tone(2400, 0.2);
wait_ms(200);
pad.tone(2400, 0.2);
}
lcd.printString("X/Y = Volume",0,4);
if (opt_volume == 0) { // Shows on screen the current volume state.
lcd.printString("Off",36,5);
} else {
lcd.printString("On",36,5);
}
}