Simple fish eat program
Dependencies: mbed mbed-rtos N5110 ShiftReg Tone
classes/Settings.cpp@8:fe51fbf81dee, 2021-03-29 (annotated)
- Committer:
- el18a2k
- Date:
- Mon Mar 29 20:32:45 2021 +0000
- Revision:
- 8:fe51fbf81dee
- Parent:
- 6:7aafcaf7cbe2
- Child:
- 11:7c1e2a9303d3
Instructions and settings complete
Who changed what in which revision?
User | Revision | Line number | New 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 | 6:7aafcaf7cbe2 | 19 | |
el18a2k | 6:7aafcaf7cbe2 | 20 | //initialise all of the board |
el18a2k | 6:7aafcaf7cbe2 | 21 | void Settings::systemINIT(N5110 &lcd, Tone &dac, Joystick &joystick){ |
el18a2k | 6:7aafcaf7cbe2 | 22 | lcd.init(); |
el18a2k | 6:7aafcaf7cbe2 | 23 | lcd.setBrightness(0.5); |
el18a2k | 6:7aafcaf7cbe2 | 24 | joystick.init(); |
el18a2k | 6:7aafcaf7cbe2 | 25 | dac.init(); |
el18a2k | 6:7aafcaf7cbe2 | 26 | shift.write(0x00); |
el18a2k | 6:7aafcaf7cbe2 | 27 | RGB_led.write(0b111); |
el18a2k | 6:7aafcaf7cbe2 | 28 | button_A.mode(PullNone); |
el18a2k | 6:7aafcaf7cbe2 | 29 | button_B.mode(PullNone); |
el18a2k | 6:7aafcaf7cbe2 | 30 | button_C.mode(PullNone); |
el18a2k | 6:7aafcaf7cbe2 | 31 | button_D.mode(PullNone); |
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 | 6:7aafcaf7cbe2 | 46 | int 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 | } |