Simple fish eat program

Dependencies:   mbed mbed-rtos N5110 ShiftReg Tone

Committer:
el18a2k
Date:
Wed Apr 21 16:26:26 2021 +0000
Revision:
13:183bd19f3d7d
Parent:
12:20ac766b3175
Child:
14:f1552b691274
bugs seem to of disapeared

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