Simple fish eat program
Dependencies: mbed mbed-rtos N5110 ShiftReg Tone
Diff: classes/Settings.cpp
- Revision:
- 8:fe51fbf81dee
- Parent:
- 6:7aafcaf7cbe2
- Child:
- 11:7c1e2a9303d3
--- a/classes/Settings.cpp Thu Mar 25 13:00:19 2021 +0000 +++ b/classes/Settings.cpp Mon Mar 29 20:32:45 2021 +0000 @@ -16,8 +16,6 @@ //objects ShiftReg shift; -Thread thread; - //initialise all of the board void Settings::systemINIT(N5110 &lcd, Tone &dac, Joystick &joystick){ @@ -44,31 +42,14 @@ } //functions for changing settings -int Settings::settingsMenu(N5110 &lcd, Tone &dac, Joystick &joystick){ +void Settings::settingsMenu(N5110 &lcd, Tone &dac, Joystick &joystick){ int rect_width = 32; - const int rightArrow[6][3] = { - { 1,0,0, }, - { 1,1,0, }, - { 1,1,1, }, - { 1,1,1, }, - { 1,1,0, }, - { 1,0,0, }, - }; - - // outputs for the state machine are used to draw Fish_1 beside the corrosponding - // menu choice - int g_setting_menu_output[2] = {7, 37}; - int state = 0; //set inital state to 0 - int direction = CENTRE; //set inital direction to remain on that state until an input is received - int x_pos; do{ lcd.clear(); lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); //draws screen border - lcd.printString("Contrast", 15, 1); - lcd.printString("Music", 15, 3); - lcd.printString("On", 15, 4); - lcd.printString("Off", 45, 4); + lcd.printString("Use L & R to", 6, 1); + lcd.printString("set contrast", 6, 2); if(joystick.get_direction() == E && rect_width < 64){ rect_width = rect_width + 16; @@ -77,8 +58,8 @@ } //contrast bar is 20 pixels high and 64 pixels long - lcd.drawRect(10,16,64,5,FILL_TRANSPARENT); //draws outer rectangle - lcd.drawRect(10,16,rect_width,5,FILL_BLACK); //draws inner rectangle + lcd.drawRect(10,30,64,5,FILL_TRANSPARENT); //draws outer rectangle + lcd.drawRect(10,30,rect_width,5,FILL_BLACK); //draws inner rectangle if(rect_width == 0){ lcd.setBrightness(0.3); @@ -96,76 +77,8 @@ lcd.setBrightness(0.7); } - /*implementation of state machine allows the determination of the position of the arrow marker - based on the users joystick input: - - inputs - state 0 1 2 where 0 is UP and 1 is DOWN 2 is CENTRE - - 0 1 1 0 - 1 0 0 1 */ - - if(joystick.get_direction() == N){ //if the joystick is moved upward, then direction is UP - direction = UP; - }else if (joystick.get_direction() == S){//if the joystick is moved downward, then direction is DOWN - direction = DOWN; - }else{ - direction = CENTRE; //if the joystick is left in the centre position then direction is CENTRE - }; - - x_pos = g_setting_menu_output[state];//x_position is the array output at position 'state' - - - //implement state machine - switch(state) { - //case for music on - case 0: - if(buttonA_state(ButtonA) == 1){ - RGB_led.write(0b101); - } - switch(direction) { - case UP: - state = 1; - break; - case DOWN: - state = 1; - break; - case CENTRE: - state = 0; - break; - } - break; - - //case for music off - case 1: - if(buttonA_state(ButtonA) == 1){ - RGB_led.write(0b110); - } - switch(direction) { - case UP: - state = 0; - break; - case DOWN: - state = 0; - break; - case CENTRE: - state = 1; - break; - } - break; - - default: - state = 0; - break; - } - - //pos / sprite x y / x y - lcd.drawSprite(x_pos,32,6,3,(int*)rightArrow); lcd.refresh(); wait_ms(1000/10); }while(buttonB_state(ButtonB) == false); - - RGB_led.write(0b111); - return 0; } \ No newline at end of file