Simple fish eat program

Dependencies:   mbed mbed-rtos N5110 ShiftReg Tone

Committer:
el18a2k
Date:
Wed Apr 21 11:08:02 2021 +0000
Revision:
11:7c1e2a9303d3
Parent:
8:fe51fbf81dee
Child:
12:20ac766b3175
highscore file writing complete

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18a2k 6:7aafcaf7cbe2 1 #include "Settings.h"
el18a2k 6:7aafcaf7cbe2 2
el18a2k 6:7aafcaf7cbe2 3 //definitions
el18a2k 6:7aafcaf7cbe2 4 #define UP 0
el18a2k 6:7aafcaf7cbe2 5 #define DOWN 1
el18a2k 6:7aafcaf7cbe2 6 #define CENTRE 2
el18a2k 6:7aafcaf7cbe2 7 #define SOUND_ON 1
el18a2k 6:7aafcaf7cbe2 8 #define SOUND_OFF 0
el18a2k 6:7aafcaf7cbe2 9
el18a2k 6:7aafcaf7cbe2 10 //attach
el18a2k 6:7aafcaf7cbe2 11 BusOut RGB_led(p24,p23,p22); //RGB bus MSB - LSB, inverted logic 1 = low
el18a2k 6:7aafcaf7cbe2 12 DigitalIn button_A(p29);
el18a2k 6:7aafcaf7cbe2 13 DigitalIn button_B(p28);
el18a2k 6:7aafcaf7cbe2 14 DigitalIn button_C(p27);
el18a2k 6:7aafcaf7cbe2 15 DigitalIn button_D(p26);
el18a2k 6:7aafcaf7cbe2 16
el18a2k 6:7aafcaf7cbe2 17 //objects
el18a2k 6:7aafcaf7cbe2 18 ShiftReg shift;
el18a2k 11:7c1e2a9303d3 19 HighScore _highscore;
el18a2k 6:7aafcaf7cbe2 20
el18a2k 6:7aafcaf7cbe2 21 //initialise all of the board
el18a2k 6:7aafcaf7cbe2 22 void Settings::systemINIT(N5110 &lcd, Tone &dac, Joystick &joystick){
el18a2k 6:7aafcaf7cbe2 23 lcd.init();
el18a2k 6:7aafcaf7cbe2 24 lcd.setBrightness(0.5);
el18a2k 6:7aafcaf7cbe2 25 joystick.init();
el18a2k 6:7aafcaf7cbe2 26 dac.init();
el18a2k 6:7aafcaf7cbe2 27 shift.write(0x00);
el18a2k 6:7aafcaf7cbe2 28 RGB_led.write(0b111);
el18a2k 6:7aafcaf7cbe2 29 button_A.mode(PullNone);
el18a2k 6:7aafcaf7cbe2 30 button_B.mode(PullNone);
el18a2k 6:7aafcaf7cbe2 31 button_C.mode(PullNone);
el18a2k 6:7aafcaf7cbe2 32 button_D.mode(PullNone);
el18a2k 11:7c1e2a9303d3 33 _highscore.write_File(100);
el18a2k 6:7aafcaf7cbe2 34 }
el18a2k 6:7aafcaf7cbe2 35
el18a2k 6:7aafcaf7cbe2 36 int Settings::buttonA_state(int ButtonA){
el18a2k 6:7aafcaf7cbe2 37 ButtonA = button_A.read();
el18a2k 6:7aafcaf7cbe2 38 return ButtonA;
el18a2k 6:7aafcaf7cbe2 39 }
el18a2k 6:7aafcaf7cbe2 40
el18a2k 6:7aafcaf7cbe2 41 int Settings::buttonB_state(int ButtonA){
el18a2k 6:7aafcaf7cbe2 42 ButtonB = button_B.read();
el18a2k 6:7aafcaf7cbe2 43 return ButtonB;
el18a2k 6:7aafcaf7cbe2 44 }
el18a2k 6:7aafcaf7cbe2 45
el18a2k 6:7aafcaf7cbe2 46 //functions for changing settings
el18a2k 8:fe51fbf81dee 47 void Settings::settingsMenu(N5110 &lcd, Tone &dac, Joystick &joystick){
el18a2k 6:7aafcaf7cbe2 48 int rect_width = 32;
el18a2k 6:7aafcaf7cbe2 49
el18a2k 6:7aafcaf7cbe2 50 do{
el18a2k 6:7aafcaf7cbe2 51 lcd.clear();
el18a2k 6:7aafcaf7cbe2 52 lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); //draws screen border
el18a2k 8:fe51fbf81dee 53 lcd.printString("Use L & R to", 6, 1);
el18a2k 8:fe51fbf81dee 54 lcd.printString("set contrast", 6, 2);
el18a2k 6:7aafcaf7cbe2 55
el18a2k 6:7aafcaf7cbe2 56 if(joystick.get_direction() == E && rect_width < 64){
el18a2k 6:7aafcaf7cbe2 57 rect_width = rect_width + 16;
el18a2k 6:7aafcaf7cbe2 58 }else if(joystick.get_direction() == W && rect_width > 0){
el18a2k 6:7aafcaf7cbe2 59 rect_width = rect_width - 16;
el18a2k 6:7aafcaf7cbe2 60 }
el18a2k 6:7aafcaf7cbe2 61
el18a2k 6:7aafcaf7cbe2 62 //contrast bar is 20 pixels high and 64 pixels long
el18a2k 8:fe51fbf81dee 63 lcd.drawRect(10,30,64,5,FILL_TRANSPARENT); //draws outer rectangle
el18a2k 8:fe51fbf81dee 64 lcd.drawRect(10,30,rect_width,5,FILL_BLACK); //draws inner rectangle
el18a2k 6:7aafcaf7cbe2 65
el18a2k 6:7aafcaf7cbe2 66 if(rect_width == 0){
el18a2k 6:7aafcaf7cbe2 67 lcd.setBrightness(0.3);
el18a2k 6:7aafcaf7cbe2 68
el18a2k 6:7aafcaf7cbe2 69 }else if(rect_width == 16){
el18a2k 6:7aafcaf7cbe2 70 lcd.setBrightness(0.4);
el18a2k 6:7aafcaf7cbe2 71
el18a2k 6:7aafcaf7cbe2 72 }else if(rect_width == 32){
el18a2k 6:7aafcaf7cbe2 73 lcd.setBrightness(0.5);
el18a2k 6:7aafcaf7cbe2 74
el18a2k 6:7aafcaf7cbe2 75 }else if(rect_width == 48){
el18a2k 6:7aafcaf7cbe2 76 lcd.setBrightness(0.6);
el18a2k 6:7aafcaf7cbe2 77
el18a2k 6:7aafcaf7cbe2 78 }else if(rect_width == 64){
el18a2k 6:7aafcaf7cbe2 79 lcd.setBrightness(0.7);
el18a2k 6:7aafcaf7cbe2 80 }
el18a2k 6:7aafcaf7cbe2 81
el18a2k 6:7aafcaf7cbe2 82 lcd.refresh();
el18a2k 6:7aafcaf7cbe2 83
el18a2k 6:7aafcaf7cbe2 84 wait_ms(1000/10);
el18a2k 6:7aafcaf7cbe2 85 }while(buttonB_state(ButtonB) == false);
el18a2k 6:7aafcaf7cbe2 86 }