void SC_setSequence() { srand(sequenceSeed); //seed the random number uint8_t randomSequence[GLOBALS_MAX_FLASH_SEQUENCE]; for (uint16_t i = 0; i < SC_sequence_length; i++) { //something with random randomSequence[i] = rand() % REGION_COUNT; } globals_setSequence(randomSequence, SC_sequence_length); globals_setSequenceIterationLength(SC_currentIndex); }
//********************************************************************************************* // verifySequence_runTest() // Tests the verifySequence state machine. // It prints instructions to the touch-screen. The user responds by tapping the // correct colors to match the sequence. // Users can test the error conditions by waiting too long to tap a color or // by tapping an incorrect color. //********************************************************************************************* void verifySequence_runTest() { display_init(); // Always must do this. buttons_init(); // Need to use the push-button package so user can quit. int16_t sequenceLength = ONE; // Start out with a sequence length of 1. verifySequence_printInstructions(sequenceLength, false); // Tell the user what to do. utils_msDelay(MESSAGE_WAIT_MS); // Give them a few seconds to read the instructions. simonDisplay_drawAllButtons() // Now, draw the buttons. // Set the test sequence and it's length. globals_setSequence(verifySequence_testSequence, MAX_TEST_SEQUENCE_LENGTH); globals_setSequenceIterationLength(sequenceLength); // Enable the verifySequence state machine. verifySequence_enable(); // Everything is interlocked, so first enable the machine. while (!(buttons_read() & BTN0))// Need to hold button until it quits as you might be stuck in a delay. { // verifySequence uses the buttonHandler state machine so you need to "tick" both of them. verifySequence_tick(); // Advance the verifySequence state machine. simonbuttonHandler_tick(); // Advance the buttonHandler state machine. utils_msDelay(ONE_MS); // Wait 1 ms. // If the verifySequence state machine has finished, check the result, otherwise just keep ticking both machines. if (verifySequence_isComplete()) { if (verifySequence_isTimeOutError()) { // Was the user too slow? verifySequence_printInfoMessage(user_time_out_e); // Yes, tell the user that they were too slow. } else if (verifySequence_isUserInputError()) { // Did the user tap the wrong color? verifySequence_printInfoMessage(user_wrong_sequence_e); // Yes, tell them so. } else { verifySequence_printInfoMessage(user_correct_sequence_e); // User was correct if you get here. } utils_msDelay(MESSAGE_WAIT_MS); // Allow the user to read the message. sequenceLength = incrementSequenceLength(sequenceLength); // Increment the sequence. globals_setSequenceIterationLength(sequenceLength); // Set the length for the verifySequence state machine. verifySequence_printInstructions(sequenceLength, V_ENABLED); // Print the instructions. utils_msDelay(MESSAGE_WAIT_MS); // Let the user read the instructions. verifySequence_drawButtons(); // Draw the buttons. verifySequence_disable(); // Interlock: first step of handshake. verifySequence_tick(); // Advance the verifySequence machine. utils_msDelay(ONE_MS); // Wait for 1 ms. verifySequence_enable(); // Interlock: second step of handshake. utils_msDelay(ONE_MS); // Wait 1 ms. } } verifySequence_printInfoMessage(user_quit_e); // Quitting, print out an informational message. }