// Prints the instructions that the user should follow when // testing the verifySequence state machine. // Takes an argument that specifies the length of the sequence so that // the instructions are tailored for the length of the sequence. // This assumes a simple incrementing pattern so that it is simple to // instruct the user. void verifySequence_printInstructions(uint8_t length, bool startingOver) { display_fillScreen(DISPLAY_BLACK); // Clear the screen. display_setTextSize(MESSAGE_TEXT_SIZE); // Make it readable. display_setCursor(MESSAGE_X, MESSAGE_Y); // Rough center. if (startingOver) { // Print a message if you start over. display_fillScreen(DISPLAY_BLACK); // Clear the screen if starting over. display_setTextColor(DISPLAY_WHITE); // Print whit text. display_println("Starting Over. "); } display_println("Tap: "); display_println(); switch (length) { case 1: display_println("red"); break; case 2: display_println("red, yellow "); break; case 3: display_println("red, yellow, blue "); break; case 4: display_println("red, yellow, blue, green "); break; default: break; } display_println("in that order."); display_println(); display_println("hold BTN0 to quit."); }
// I used a busy-wait delay (utils_msDelay) that uses a for-loop and just blocks until the time has passed. // When you implement the game, you CANNOT use this function as we discussed in class. Implement the delay // using the non-blocking state-machine approach discussed in class. void simonDisplay_runTest(uint16_t touchCount) { display_init(); // Always initialize the display. char str[MAX_STR]; // Enough for some simple printing. uint8_t regionNumber; uint16_t touches = 0; // Write an informational message and wait for the user to touch the LCD. display_fillScreen(DISPLAY_BLACK); // clear the screen. display_setCursor(0, display_height()/2); // display_setTextSize(TEXT_SIZE); display_setTextColor(DISPLAY_RED, DISPLAY_BLACK); sprintf(str, "Touch and release to start the Simon demo."); display_println(str); display_println(); sprintf(str, "Demo will terminate after %d touches.", touchCount); display_println(str); while (!display_isTouched()); // Wait here until the screen is touched. while (display_isTouched()); // Now wait until the touch is released. display_fillScreen(DISPLAY_BLACK); // Clear the screen. simonDisplay_drawAllButtons(); // Draw all of the buttons. bool touched = false; // Keep track of when the pad is touched. int16_t x, y; // Use these to keep track of coordinates. uint8_t z; // This is the relative touch pressure. while (touches < touchCount) { // Run the loop according to the number of touches passed in. if (!display_isTouched() && touched) { // user has stopped touching the pad. simonDisplay_drawSquare(regionNumber, true); // Erase the square. simonDisplay_drawButton(regionNumber); // DISPLAY_REDraw the button. touched = false; // Released the touch, set touched to false. } else if (display_isTouched() && !touched) { // User started touching the pad. touched = true; // Just touched the pad, set touched = true. touches++; // Keep track of the number of touches. display_clearOldTouchData(); // Get rid of data from previous touches. // Must wait this many milliseconds for the chip to do analog processing. utils_msDelay(TOUCH_PANEL_ANALOG_PROCESSING_DELAY_IN_MS); display_getTouchedPoint(&x, &y, &z); // After the wait, get the touched point. regionNumber = simonDisplay_computeRegionNumber(x, y);// Compute the region number. simonDisplay_drawSquare(regionNumber, false); // Draw the square (erase = false). } } // Done with the demo, write an informational message to the user. display_fillScreen(DISPLAY_BLACK); // clear the screen. display_setCursor(0, display_height()/2); // Place the cursor in the middle of the screen. display_setTextSize(2); // Make it readable. display_setTextColor(DISPLAY_RED, DISPLAY_BLACK); // red is foreground color, black is background color. sprintf(str, "Simon demo terminated"); // Format a string using sprintf. display_println(str); // Print it to the LCD. sprintf(str, "after %d touches.", touchCount); // Format the rest of the string. display_println(str); // Print it to the LCD. }
int main() { // init the display so we can draw on it! display_init(); // fill the display with black so it's all ready to have buttons drawn on it display_fillScreen(DISPLAY_BLACK); // Init all interrupts (but does not enable the interrupts at the devices). // Prints an error message if an internal failure occurs because the argument = true. interrupts_initAll(true); interrupts_setPrivateTimerLoadValue(TIMER_LOAD_VALUE); printf("timer load value:%ld\n\r", (int32_t) TIMER_LOAD_VALUE); u32 privateTimerTicksPerSecond = interrupts_getPrivateTimerTicksPerSecond(); printf("private timer ticks per second: %ld\n\r", privateTimerTicksPerSecond); interrupts_enableTimerGlobalInts(); // Initialization of the clock display is not time-dependent, do it outside of the state machine. // clockDisplay_init(); // Start the private ARM timer running. interrupts_startArmPrivateTimer(); // Enable interrupts at the ARM. interrupts_enableArmInts(); // The while-loop just waits until the total number of timer ticks have occurred before proceeding. while (interrupts_isrInvocationCount() < (TOTAL_SECONDS * privateTimerTicksPerSecond)); // All done, now disable interrupts and print out the interrupt counts. interrupts_disableArmInts(); printf("isr invocation count: %ld\n\r", interrupts_isrInvocationCount()); printf("internal interrupt count: %ld\n\r", isr_functionCallCount); return 0; }
// Inits the tic-tac-toe display, draws the lines that form the board. void ticTacToeDisplay_init(){ display_init(); // Must init all of the software and underlying hardware for LCD. display_fillScreen(DISPLAY_BLACK); // Blank the screen. display_setRotation(true); buttons_init(); ticTacToeDisplay_drawBoardLines(); /* ticTacToeDisplay_drawX(TICTACTOE_DISP_COLUMN_0, TICTACTOE_DISP_ROW_0); ticTacToeDisplay_drawX(TICTACTOE_DISP_COLUMN_1, TICTACTOE_DISP_ROW_0); ticTacToeDisplay_drawX(TICTACTOE_DISP_COLUMN_2, TICTACTOE_DISP_ROW_0); ticTacToeDisplay_drawX(TICTACTOE_DISP_COLUMN_0, TICTACTOE_DISP_ROW_1); ticTacToeDisplay_drawX(TICTACTOE_DISP_COLUMN_1, TICTACTOE_DISP_ROW_1); ticTacToeDisplay_drawX(TICTACTOE_DISP_COLUMN_2, TICTACTOE_DISP_ROW_1); ticTacToeDisplay_drawX(TICTACTOE_DISP_COLUMN_0, TICTACTOE_DISP_ROW_2); ticTacToeDisplay_drawX(TICTACTOE_DISP_COLUMN_1, TICTACTOE_DISP_ROW_2); ticTacToeDisplay_drawX(TICTACTOE_DISP_COLUMN_2, TICTACTOE_DISP_ROW_2); */ /* ticTacToeDisplay_drawO(TICTACTOE_DISP_COLUMN_0, TICTACTOE_DISP_ROW_0); ticTacToeDisplay_drawO(TICTACTOE_DISP_COLUMN_0, TICTACTOE_DISP_ROW_1); ticTacToeDisplay_drawO(TICTACTOE_DISP_COLUMN_0, TICTACTOE_DISP_ROW_2); ticTacToeDisplay_drawO(TICTACTOE_DISP_COLUMN_1, TICTACTOE_DISP_ROW_0); ticTacToeDisplay_drawO(TICTACTOE_DISP_COLUMN_1, TICTACTOE_DISP_ROW_1); ticTacToeDisplay_drawO(TICTACTOE_DISP_COLUMN_1, TICTACTOE_DISP_ROW_2); ticTacToeDisplay_drawO(TICTACTOE_DISP_COLUMN_2, TICTACTOE_DISP_ROW_0); ticTacToeDisplay_drawO(TICTACTOE_DISP_COLUMN_2, TICTACTOE_DISP_ROW_1); ticTacToeDisplay_drawO(TICTACTOE_DISP_COLUMN_2, TICTACTOE_DISP_ROW_2);*/ }
// Prints out informational messages based upon a message type (see above). void verifySequence_printInfoMessage(verifySequence_infoMessage_t messageType) { // Setup text color, position and clear the screen. display_setTextColor(DISPLAY_WHITE); display_setCursor(MESSAGE_X, MESSAGE_Y); display_fillScreen(DISPLAY_BLACK); switch(messageType) { case user_time_out_e: // Tell the user that they typed too slowly. display_println("Error:"); display_println(); display_println(" User tapped sequence"); display_println(" too slowly."); break; case user_wrong_sequence_e: // Tell the user that they tapped the wrong color. display_println("Error: "); display_println(); display_println(" User tapped the"); display_println(" wrong sequence."); break; case user_correct_sequence_e: // Tell the user that they were correct. display_println("User tapped"); display_println("the correct sequence."); break; case user_quit_e: // Acknowledge that you are quitting the test. display_println("quitting runTest()."); break; default: break; } }
void TicTacToeDisplay_complete() { display_fillScreen(DISPLAY_BLACK); display_setTextColor(DISPLAY_RED); display_setTextSize(4); display_println("TEST COMPLETE" ); }
void ticTacToeDisplay_init() { display_init(); // Must initialize all of the software and underlying hardware for LCD. display_fillScreen(TICTACTOEDISPLAY_BLACK); // Blank the screen with all black display_setTextColor(TICTACTOEDISPLAY_GREEN); // Make the text green. display_setTextSize(TICTACTOEDISPLAY_TEXT_SIZE); // this sets the text size ticTacToeDisplay_drawBoardLines();//draw the board lines }
// Draw the initial splash (instruction) screen. void wamDisplay_drawSplashScreen() { display_setTextSize(WAM_D_NORMAL_TEXT); display_fillScreen(DISPLAY_BLACK); //clear screen //position in center ish display_setCursor(WAM_D_MESSAGE_OFFSET*DISPLAY_CHAR_WIDTH * WAM_D_NORMAL_TEXT, WAM_D_NORMAL_TEXT*DISPLAY_CHAR_HEIGHT); //print display_println(WAM_INSTRUCTIONS); }
void ticTacToeDisplay_gameOver() { display_init(); // Must init all of the software and underlying hardware for LCD. display_fillScreen(DISPLAY_BLACK); // Blank the screen. display_setRotation(true); ticTacToeDisplay_drawX(TICTACTOE_DISP_ROW_0,TICTACTOE_DISP_COLUMN_0); ticTacToeDisplay_drawX(TICTACTOE_DISP_ROW_0,TICTACTOE_DISP_COLUMN_2); display_drawFastHLine(display_width()/3, display_height()/2, display_width()/3, DISPLAY_CYAN); display_setCursor(TICTACTOE_DISP_COLUMN_1_PT,TICTACTOE_DISP_ROW_2_PT); display_println("Game Over"); }
int main() { display_init(); // Must init all of the software and underlying hardware for LCD. display_fillScreen(DISPLAY_BLACK); // Blank the screen. display_setRotation(0); display_drawLine(0,0,240,320,GREEN); display_drawLine(240,0,0,320 ,GREEN); display_drawCircle(120,80,30,RED); display_fillCircle(120,240,30,RED); display_drawTriangle(90,160,45,134,45,186,YELLOW); display_fillTriangle(150,160,195,134,195,186,YELLOW); }
void buttons_runTest() { buttons_init(); // Initialize buttons display_init(); // Initialize display, which sets Rotation = 1 by default display_fillScreen(DISPLAY_BLACK); // blank the screen display_setTextColor(DISPLAY_BLACK); // Change text color to black display_setTextSize(BUTTONS_TEXT_SIZE); // Make text larger // Set the values of the global variables x_max = display_width(); y_max = display_height(); // Set the values of screen positions x_fourth = FOURTH(x_max); x_half = HALF(x_max); x_three_fourths = THREE_FOURTHS(x_max); y_fourth = FOURTH(y_max); y_half = HALF(y_max); y_three_fourths = THREE_FOURTHS(y_max); // Do an initial read of button values int32_t buttonValues = buttons_read(); // Until all 4 BTNS are pressed simultaneously, write info to the LCD while (buttonValues != BUTTONS_ALL_BTNS_ON) { // Draw the Rects/Text on the LCD corresponding to current buttons buttons_write_LCD(buttonValues); // Poll new value of buttons buttonValues = buttons_read(); } // After all buttons are pushed simultaneously, finish test. display_fillScreen(DISPLAY_BLACK); // blank screen display_setTextColor(DISPLAY_CYAN); // change text color display_setCursor(0,0); // reset cursor to origin display_println("Button Test Finished!"); // print that the test is complete }
// Draw the game-over screen. void wamDisplay_drawGameOverScreen() { wamDisplay_freeMemory(currentBoardsize); //deallocate the memory display_fillScreen(DISPLAY_BLACK); //clear screen //center and move down the Game Over message display_setCursor(WAM_D_MESSAGE_OFFSET*DISPLAY_CHAR_WIDTH * WAM_D_BIG_TEXT, WAM_D_MESSAGE_OFFSET*DISPLAY_CHAR_HEIGHT*WAM_D_BIG_TEXT); display_setTextSize(WAM_D_BIG_TEXT); //set size of text display_println(WAM_D_GAME_OVER_MESSAGE1); //print GAME OVER display_setTextSize(WAM_D_NORMAL_TEXT); //lower text size sprintf(gameOverStatString, WAM_D_GAME_OVER_MESSAGE2_FORMAT, oldHits, oldMisses, currentLevel); display_println(gameOverStatString); //display wamDisplay_resetAllScoresAndLevel(); //after printing, reset it all. }
int main() { srand(LARGE_PRIME_NUMBER); // Initialize the GPIO LED driver and print out an error message if it fails (argument = true). // You need to init the LEDs so that LD4 can function as a heartbeat. leds_init(true); // Init all interrupts (but does not enable the interrupts at the devices). // Prints an error message if an internal failure occurs because the argument = true. interrupts_initAll(true); interrupts_setPrivateTimerLoadValue(TIMER_LOAD_VALUE); u32 privateTimerTicksPerSecond = interrupts_getPrivateTimerTicksPerSecond(); printf("private timer ticks per second: %ld\n\r", privateTimerTicksPerSecond); // Allow the timer to generate interrupts. interrupts_enableTimerGlobalInts(); // Initialization of the clock display is not time-dependent, do it outside of the state machine. //TicTacToeDisplay_init(); display_init(); display_fillScreen(DISPLAY_BLACK); buttons_init(); // Keep track of your personal interrupt count. Want to make sure that you don't miss any interrupts. int32_t personalInterruptCount = 0; // Start the private ARM timer running. interrupts_startArmPrivateTimer(); // Enable interrupts at the ARM. interrupts_enableArmInts(); // interrupts_isrInvocationCount() returns the number of times that the timer ISR was invoked. // This value is maintained by the timer ISR. Compare this number with your own local // interrupt count to determine if you have missed any interrupts. while (interrupts_isrInvocationCount() < (TOTAL_SECONDS * privateTimerTicksPerSecond)) { if (interrupts_isrFlagGlobal) { // This is a global flag that is set by the timer interrupt handler. // Count ticks. double duration0; personalInterruptCount++; SimonControl_tick(); verifySequence_tick(); flashSequence_tick(); simonbuttonHandler_tick(); interrupts_isrFlagGlobal = FLAG_DOWN; } } interrupts_disableArmInts(); printf("isr invocation count: %ld\n\r", interrupts_isrInvocationCount()); printf("internal interrupt count: %ld\n\r", personalInterruptCount); return 0; }
// Init function void clockDisplay_init() { display_init(); // Must init all of the software and underlying hardware for LCD. display_fillScreen(CLOCKDISPLAY__BLACK); // Blank the screen. display_setRotation(true); display_setTextColor(CLOCKDISPLAY_GREEN); display_setTextSize(CLOCKDISPLAY_DISP_TXT_SIZE); clockDisplay_updateTimeDisplay(true); // Sets the colons on display; they never change display_drawChar(clockDisplay_x_char (CLOCKDISPLAY_CHAR_5),clockDisplay_y_char (CLOCKDISPLAY_CHAR_0),Colon,CLOCKDISPLAY_GREEN,CLOCKDISPLAY__BLACK,CLOCKDISPLAY_DISP_TXT_SIZE); display_drawChar(clockDisplay_x_char (CLOCKDISPLAY_CHAR_2),clockDisplay_y_char (CLOCKDISPLAY_CHAR_0),Colon,CLOCKDISPLAY_GREEN,CLOCKDISPLAY__BLACK,CLOCKDISPLAY_DISP_TXT_SIZE); clockDisplay_Triangle(CLOCKDISPLAY_DISP_TRIANGLE_0 ,CLOCKDISPLAY_GREEN); clockDisplay_Triangle(CLOCKDISPLAY_DISP_TRIANGLE_1 ,CLOCKDISPLAY_GREEN); clockDisplay_Triangle(CLOCKDISPLAY_DISP_TRIANGLE_2 ,CLOCKDISPLAY_GREEN); clockDisplay_Triangle(CLOCKDISPLAY_DISP_TRIANGLE_3 ,CLOCKDISPLAY_GREEN); clockDisplay_Triangle(CLOCKDISPLAY_DISP_TRIANGLE_4 ,CLOCKDISPLAY_GREEN); clockDisplay_Triangle(CLOCKDISPLAY_DISP_TRIANGLE_5 ,CLOCKDISPLAY_GREEN); }
// Just clears the screen and draws the four buttons used in Simon. void verifySequence_drawButtons() { display_fillScreen(DISPLAY_BLACK); simonDisplay_drawAllButtons(); // Draw the four buttons. }
int main() { //buttonHandler_runTest(10); //flashSequence_runTest(); //verifySequence_runTest(); // The formula for computing the load value is based upon the formula from 4.1.1 (calculating timer intervals) // in the Cortex-A9 MPCore Technical Reference Manual 4-2. // Assuming that the prescaler = 0, the formula for computing the load value based upon the desired period is: // load-value = (period * timer-clock) - 1 // Initialize the GPIO LED driver and print out an error message if it fails (argument = true). // You need to init the LEDs so that LD4 can function as a heartbeat. leds_init(true); // Init all interrupts (but does not enable the interrupts at the devices). // Prints an error message if an internal failure occurs because the argument = true. interrupts_initAll(true); interrupts_setPrivateTimerLoadValue(TIMER_LOAD_VALUE); u32 privateTimerTicksPerSecond = interrupts_getPrivateTimerTicksPerSecond(); printf("private timer ticks per second: %ld\n\r", privateTimerTicksPerSecond); // Allow the timer to generate interrupts. interrupts_enableTimerGlobalInts(); // Initialization of the Simon game state machines is not time-dependent so we do it outside of the state machine. display_init(); display_fillScreen(DISPLAY_BLACK); // Keep track of your personal interrupt count. Want to make sure that you don't miss any interrupts. int32_t personalInterruptCount = 0; // Start the private ARM timer running. interrupts_startArmPrivateTimer(); // Enable interrupts at the ARM. interrupts_enableArmInts(); // interrupts_isrInvocationCount() returns the number of times that the timer ISR was invoked. // This value is maintained by the timer ISR. Compare this number with your own local // interrupt count to determine if you have missed any interrupts. double *seconds; while (interrupts_isrInvocationCount() < (TOTAL_SECONDS * privateTimerTicksPerSecond)) { if (interrupts_isrFlagGlobal) { // This is a global flag that is set by the timer interrupt handler. // Count ticks. personalInterruptCount++; verifySequence_tick(); flashSequence_tick(); buttonHandler_tick(); intervalTimer_start(1); simonControl_tick(); intervalTimer_stop(1); intervalTimer_getTotalDurationInSeconds(1,seconds); printf("%f \r\n",*seconds); //printf("interrupt count: %lu \r\n", interrupts_isrInvocationCount()); intervalTimer_reset(1); interrupts_isrFlagGlobal = 0; } } interrupts_disableArmInts(); printf("isr invocation count: %ld\n\r", interrupts_isrInvocationCount()); printf("internal interrupt count: %ld\n\r", personalInterruptCount); return 0; }
void TicTacToeDisplay_init() { // Must init all of the software and underlying hardware for LCD. display_fillScreen(DISPLAY_BLACK); // Blank the screen. TicTacToeDisplay_drawBoardLines(); }
void buttons_runTest() { buttons_init(); // Initialize the display for writing. display_init(); // Clear the screen; make the whole thing black. display_fillScreen(DISPLAY_BLACK); // Set up a var for storing the current value of the buttons. // This will be updated every time our while loop cycles. uint32_t newVal = 0; // Set up a var for storing the previous value of the buttons. // This will be updated every time our while loop cycles. uint32_t lastVal = 0; // Set the text size to a value of 2. display_setTextSize(BUTTONS_TEXT_SIZE); // As long as all four buttons are not all pressed at once, do this: while(newVal ^ BUTTONS_ARE_ALL_PRESSED) { // Copy newVal into lastVal because we're going to update newVal. lastVal = newVal; // Read the state of the buttons into newVal. newVal = buttons_read(); // We need to check whether BUTTONS_BUTTON1's corresponding square has // already been drawn. We don't want to draw it again if it's // already there. if(!(lastVal & BUTTONS_BUTTON1) && (newVal & BUTTONS_BUTTON1)) { // Fill the far right square with yellow. display_fillRect(BUTTONS_BUTTON1_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_YELLOW); // Set our text cursor to a good place in the center of the square. display_setCursor(BUTTONS_BUTTON1_CURSOR_X_CORD, BUTTONS_ALL_BUTTONS_CURSOR_Y_CORD); // Make the text color black. display_setTextColor(DISPLAY_BLACK); // Write BTN0 in the center of the square. display_println(BUTTONS_BUTTON1_TEXT); } // If the square is drawn, and button 1 is no longer pressed: else if((lastVal & BUTTONS_BUTTON1) && !(newVal & BUTTONS_BUTTON1)) { // Write a black square on top of the yellow square. display_fillRect(BUTTONS_BUTTON1_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLACK); } // Repeat the process for BUTTONS_BUTTON1 for all other buttons: if(!(lastVal & BUTTONS_BUTTON2) && (newVal & BUTTONS_BUTTON2)) { // Draw a green square display_fillRect(BUTTONS_BUTTON2_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_GREEN); // Set the cursor display_setCursor(BUTTONS_BUTTON2_CURSOR_X_CORD, BUTTONS_ALL_BUTTONS_CURSOR_Y_CORD); // Set text color to black display_setTextColor(DISPLAY_BLACK); // Write BTN1 display_println(BUTTONS_BUTTON2_TEXT); } // If the BUTTONS_BUTTON2 square is there and BUTTONS_BUTTON2 is no longer pressed: else if((lastVal & BUTTONS_BUTTON2) && !(newVal & BUTTONS_BUTTON2)) { // Draw a black square over the top of the green one display_fillRect(BUTTONS_BUTTON2_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLACK); } // If BUTTONS_BUTTON3 is pressed and the square is not already drawn: if(!(lastVal & BUTTONS_BUTTON3) && (newVal & BUTTONS_BUTTON3)) { // Draw a red rectangle display_fillRect(BUTTONS_BUTTON3_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_RED); // Set the cursor display_setCursor(BUTTONS_BUTTON3_CURSOR_X_CORD, BUTTONS_ALL_BUTTONS_CURSOR_Y_CORD); // Set the text color to white display_setTextColor(DISPLAY_WHITE); // Write BTN2 to the screen display_println(BUTTONS_BUTTON3_TEXT); } // If BUTTONS_BUTTON3 is no longer pressed and the square is on the screen: else if((lastVal & BUTTONS_BUTTON3) && !(newVal & BUTTONS_BUTTON3)) { // Draw a black rectangle over the top of the red one display_fillRect(BUTTONS_BUTTON3_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLACK); } // If BUTTONS_BUTTON4 is pressed and the square isn't on the screen: if(!(lastVal & BUTTONS_BUTTON4) && (newVal & BUTTONS_BUTTON4)) { // Draw a blue rectangle display_fillRect(0, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLUE); // Set the cursor display_setCursor(BUTTONS_BUTTON4_CURSOR_X_CORD, BUTTONS_ALL_BUTTONS_CURSOR_Y_CORD); // Set the text to be white display_setTextColor(DISPLAY_WHITE); // Write BTN3 to the screen display_println(BUTTONS_BUTTON4_TEXT); } // If BUTTONS_BUTTON4 is no longer pressed and the square is on the screen: else if((lastVal & BUTTONS_BUTTON4) && !(newVal & BUTTONS_BUTTON4)) { // Draw a black square over the blue one display_fillRect(0, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLACK); } } // Once all 4 buttons are pressed simultaneously, // Draw a black square over the top part of the screen // To reset it. display_fillRect(0, 0, BUTTONS_SCREEN_WIDTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLACK); }
void simonControl_tick() { SC_debugStatePrint(); /// //ACTIONS*********************************************************************** switch(SC_State) { case SC_init_st: //do nothing break; case SC_instructions_st: display_setTextColor(DISPLAY_WHITE); display_setCursor(SC_INSTRUCTION_CURSORX,SC_INSTRUCTION_CURSORY); display_setTextSize(SC_INSTRUCTION_TEXTSIZE); display_println(SC_INSTRUCTIONS); break; case SC_wait_first_touch_st: // do nothing break; case SC_get_sequence_st: SC_currentScore = 0; //reset SC_setSequence(); break; case SC_flash_sequence_st: //do nothing break; case SC_verify_sequence_st: //do nothing break; case SC_error_st: errorTimer++; if (verifySequence_isTimeOutError()) // user didn't press { display_setTextSize(SC_TEXTSIZE); display_println(ERROR_MESSAGE_TIMEOUT); } else if (verifySequence_isUserInputError()) //pressed wrong input { display_setTextSize(SC_TEXTSIZE); display_println(ERROR_MESSAGE_INPUT); } verifySequence_disable(); //set this here so we can read these flags. disable resets the error flags break; case SC_print_score_st: sprintf(maxScoreString, SC_HIGHSCORE_MESSAGE, SC_maxScore); display_setTextSize(SC_TEXTSIZE); //decrease text size display_println(maxScoreString); //reset scores, index, and sequence SC_currentIndex = 1; //reset to 1. since this is sequence length, when we setSequence, don't put to zero SC_maxScore = 0; //reset errorTimer = 0; //reset timer lvlMessageTimer = 0; break; case SC_level_complete_st: lvlMessageTimer++; if(printFlag) //set a flag so it doesn't keep being printed { display_println(SC_LVL_MESSAGE); printFlag = false; //switch flag } break; default: printf(SC_ERROR_MESSAGE); //invalid state break; } //TRANSITIONS*********************************************************************** switch(SC_State) { case SC_init_st: SC_State = SC_instructions_st; //just go to instructions break; case SC_instructions_st: SC_State = SC_wait_first_touch_st; //go wait after drawing. break; case SC_wait_first_touch_st: if (display_isTouched()) //if touched, move ahead { SC_State = SC_get_sequence_st; display_fillScreen(DISPLAY_BLACK); //clear screen of instructions } break; case SC_get_sequence_st: SC_State = SC_flash_sequence_st; flashSequence_enable(); break; case SC_flash_sequence_st: if (flashSequence_completed()) { SC_State = SC_verify_sequence_st; //go to verify flashSequence_disable(); //disable flash machine simonDisplay_drawAllButtons(); //draw the buttons upon exit verifySequence_enable(); } break; case SC_verify_sequence_st: if (verifySequence_isComplete()) //done verifying { //if there a time out error or wrong input error if (verifySequence_isTimeOutError() || verifySequence_isUserInputError()) //no errors { SC_State = SC_error_st; display_fillScreen(DISPLAY_BLACK); //clear buttons off screen } //level complete else if (globals_getSequenceIterationLength() == SC_sequence_length) { SC_sequence_length++; SC_State = SC_level_complete_st; verifySequence_disable(); display_fillScreen(DISPLAY_BLACK); //clear buttons off screen SC_currentIndex = 1; //reset SC_maxScore = SC_currentScore; } else { SC_State = SC_flash_sequence_st; flashSequence_enable(); SC_currentIndex++; //how many to flash? globals_setSequenceIterationLength(SC_currentIndex); //udate how many to falsh verifySequence_disable(); display_fillScreen(DISPLAY_BLACK); //clear buttons off screen SC_currentScore++; if (SC_currentScore > SC_maxScore) //before first level is complete, maxScore doesn't get set { SC_maxScore = SC_currentScore; //this mostly before first level is complete } } } break; case SC_error_st: if (errorTimer >= SC_ERROR_EXPIRE) { SC_State = SC_print_score_st; //print highest score display_fillScreen(DISPLAY_BLACK); } break; case SC_print_score_st: SC_State = SC_instructions_st; SC_maxScore = 0; //reset the maxScore! sequenceSeed++; //change the seed break; case SC_level_complete_st: if (lvlMessageTimer > SC_LVL_MESSAGE_EXPIRE) //timed out { SC_State = SC_print_score_st; } else if (display_isTouched()) { SC_State = SC_instructions_st; display_fillScreen(DISPLAY_BLACK); // clear screen sequenceSeed++; //change the seed printFlag = true; //rest print flag } break; default: printf(SC_ERROR_MESSAGE); break; } }