Simple fish eat program
Dependencies: mbed mbed-rtos N5110 ShiftReg Tone
classes/Settings.cpp@14:f1552b691274, 2021-08-02 (annotated)
- Committer:
- el18a2k
- Date:
- Mon Aug 02 14:35:02 2021 +0000
- Revision:
- 14:f1552b691274
- Parent:
- 13:183bd19f3d7d
final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el18a2k | 14:f1552b691274 | 1 | /* Fish Eat Game v2.0 |
el18a2k | 14:f1552b691274 | 2 | * Author: Andrew Knowles |
el18a2k | 14:f1552b691274 | 3 | * Date: 21/04/2021 |
el18a2k | 14:f1552b691274 | 4 | * Note: See hearder files for additional recognistion */ |
el18a2k | 14:f1552b691274 | 5 | |
el18a2k | 6:7aafcaf7cbe2 | 6 | #include "Settings.h" |
el18a2k | 6:7aafcaf7cbe2 | 7 | |
el18a2k | 6:7aafcaf7cbe2 | 8 | //attach |
el18a2k | 6:7aafcaf7cbe2 | 9 | BusOut RGB_led(p24,p23,p22); //RGB bus MSB - LSB, inverted logic 1 = low |
el18a2k | 6:7aafcaf7cbe2 | 10 | DigitalIn button_A(p29); |
el18a2k | 6:7aafcaf7cbe2 | 11 | DigitalIn button_B(p28); |
el18a2k | 6:7aafcaf7cbe2 | 12 | DigitalIn button_C(p27); |
el18a2k | 6:7aafcaf7cbe2 | 13 | DigitalIn button_D(p26); |
el18a2k | 6:7aafcaf7cbe2 | 14 | |
el18a2k | 6:7aafcaf7cbe2 | 15 | //objects |
el18a2k | 6:7aafcaf7cbe2 | 16 | ShiftReg shift; |
el18a2k | 11:7c1e2a9303d3 | 17 | HighScore _highscore; |
el18a2k | 6:7aafcaf7cbe2 | 18 | |
el18a2k | 6:7aafcaf7cbe2 | 19 | //initialise all of the board |
el18a2k | 6:7aafcaf7cbe2 | 20 | void Settings::systemINIT(N5110 &lcd, Tone &dac, Joystick &joystick){ |
el18a2k | 6:7aafcaf7cbe2 | 21 | lcd.init(); |
el18a2k | 6:7aafcaf7cbe2 | 22 | lcd.setBrightness(0.5); |
el18a2k | 6:7aafcaf7cbe2 | 23 | joystick.init(); |
el18a2k | 6:7aafcaf7cbe2 | 24 | dac.init(); |
el18a2k | 6:7aafcaf7cbe2 | 25 | shift.write(0x00); |
el18a2k | 6:7aafcaf7cbe2 | 26 | RGB_led.write(0b111); |
el18a2k | 6:7aafcaf7cbe2 | 27 | button_A.mode(PullNone); |
el18a2k | 6:7aafcaf7cbe2 | 28 | button_B.mode(PullNone); |
el18a2k | 6:7aafcaf7cbe2 | 29 | button_C.mode(PullNone); |
el18a2k | 6:7aafcaf7cbe2 | 30 | button_D.mode(PullNone); |
el18a2k | 12:20ac766b3175 | 31 | _highscore.writeFile(100); |
el18a2k | 6:7aafcaf7cbe2 | 32 | } |
el18a2k | 6:7aafcaf7cbe2 | 33 | |
el18a2k | 6:7aafcaf7cbe2 | 34 | int Settings::buttonA_state(int ButtonA){ |
el18a2k | 6:7aafcaf7cbe2 | 35 | ButtonA = button_A.read(); |
el18a2k | 6:7aafcaf7cbe2 | 36 | return ButtonA; |
el18a2k | 6:7aafcaf7cbe2 | 37 | } |
el18a2k | 6:7aafcaf7cbe2 | 38 | |
el18a2k | 6:7aafcaf7cbe2 | 39 | int Settings::buttonB_state(int ButtonA){ |
el18a2k | 6:7aafcaf7cbe2 | 40 | ButtonB = button_B.read(); |
el18a2k | 6:7aafcaf7cbe2 | 41 | return ButtonB; |
el18a2k | 6:7aafcaf7cbe2 | 42 | } |
el18a2k | 6:7aafcaf7cbe2 | 43 | |
el18a2k | 6:7aafcaf7cbe2 | 44 | //functions for changing settings |
el18a2k | 8:fe51fbf81dee | 45 | void Settings::settingsMenu(N5110 &lcd, Tone &dac, Joystick &joystick){ |
el18a2k | 12:20ac766b3175 | 46 | rect_width = 32; |
el18a2k | 6:7aafcaf7cbe2 | 47 | |
el18a2k | 6:7aafcaf7cbe2 | 48 | do{ |
el18a2k | 6:7aafcaf7cbe2 | 49 | lcd.clear(); |
el18a2k | 6:7aafcaf7cbe2 | 50 | lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); //draws screen border |
el18a2k | 8:fe51fbf81dee | 51 | lcd.printString("Use L & R to", 6, 1); |
el18a2k | 8:fe51fbf81dee | 52 | lcd.printString("set contrast", 6, 2); |
el18a2k | 6:7aafcaf7cbe2 | 53 | |
el18a2k | 6:7aafcaf7cbe2 | 54 | if(joystick.get_direction() == E && rect_width < 64){ |
el18a2k | 6:7aafcaf7cbe2 | 55 | rect_width = rect_width + 16; |
el18a2k | 6:7aafcaf7cbe2 | 56 | }else if(joystick.get_direction() == W && rect_width > 0){ |
el18a2k | 6:7aafcaf7cbe2 | 57 | rect_width = rect_width - 16; |
el18a2k | 6:7aafcaf7cbe2 | 58 | } |
el18a2k | 6:7aafcaf7cbe2 | 59 | |
el18a2k | 6:7aafcaf7cbe2 | 60 | //contrast bar is 20 pixels high and 64 pixels long |
el18a2k | 8:fe51fbf81dee | 61 | lcd.drawRect(10,30,64,5,FILL_TRANSPARENT); //draws outer rectangle |
el18a2k | 8:fe51fbf81dee | 62 | lcd.drawRect(10,30,rect_width,5,FILL_BLACK); //draws inner rectangle |
el18a2k | 6:7aafcaf7cbe2 | 63 | |
el18a2k | 6:7aafcaf7cbe2 | 64 | if(rect_width == 0){ |
el18a2k | 6:7aafcaf7cbe2 | 65 | lcd.setBrightness(0.3); |
el18a2k | 6:7aafcaf7cbe2 | 66 | |
el18a2k | 6:7aafcaf7cbe2 | 67 | }else if(rect_width == 16){ |
el18a2k | 6:7aafcaf7cbe2 | 68 | lcd.setBrightness(0.4); |
el18a2k | 6:7aafcaf7cbe2 | 69 | |
el18a2k | 6:7aafcaf7cbe2 | 70 | }else if(rect_width == 32){ |
el18a2k | 6:7aafcaf7cbe2 | 71 | lcd.setBrightness(0.5); |
el18a2k | 6:7aafcaf7cbe2 | 72 | |
el18a2k | 6:7aafcaf7cbe2 | 73 | }else if(rect_width == 48){ |
el18a2k | 6:7aafcaf7cbe2 | 74 | lcd.setBrightness(0.6); |
el18a2k | 6:7aafcaf7cbe2 | 75 | |
el18a2k | 6:7aafcaf7cbe2 | 76 | }else if(rect_width == 64){ |
el18a2k | 6:7aafcaf7cbe2 | 77 | lcd.setBrightness(0.7); |
el18a2k | 6:7aafcaf7cbe2 | 78 | } |
el18a2k | 6:7aafcaf7cbe2 | 79 | |
el18a2k | 6:7aafcaf7cbe2 | 80 | lcd.refresh(); |
el18a2k | 6:7aafcaf7cbe2 | 81 | |
el18a2k | 6:7aafcaf7cbe2 | 82 | wait_ms(1000/10); |
el18a2k | 6:7aafcaf7cbe2 | 83 | }while(buttonB_state(ButtonB) == false); |
el18a2k | 6:7aafcaf7cbe2 | 84 | } |