// Convenience function that draws all of the buttons. void simonDisplay_drawAllButtons() { //top left red button display_fillRect(SIMON_DISPLAY_BTN_OFFSET_X, SIMON_DISPLAY_BTN_OFFSET_Y, SIMON_DISPLAY_BUTTON_WIDTH, SIMON_DISPLAY_BUTTON_HEIGHT, SIMON_DISPLAY_RED); //top right yellow button display_fillRect(SIMON_DISPLAY_HALF_WIDTH + SIMON_DISPLAY_BTN_OFFSET_X, SIMON_DISPLAY_BTN_OFFSET_Y, SIMON_DISPLAY_BUTTON_WIDTH, SIMON_DISPLAY_BUTTON_HEIGHT, SIMON_DISPLAY_YELLOW); //bottom left blue button display_fillRect(SIMON_DISPLAY_BTN_OFFSET_X, SIMON_DISPLAY_HALF_HEIGHT + SIMON_DISPLAY_BTN_OFFSET_Y, SIMON_DISPLAY_BUTTON_WIDTH, SIMON_DISPLAY_BUTTON_HEIGHT, SIMON_DISPLAY_BLUE); //bottom right green button display_fillRect(SIMON_DISPLAY_HALF_WIDTH + SIMON_DISPLAY_BTN_OFFSET_X, SIMON_DISPLAY_HALF_HEIGHT + SIMON_DISPLAY_BTN_OFFSET_Y, SIMON_DISPLAY_BUTTON_WIDTH, SIMON_DISPLAY_BUTTON_HEIGHT, SIMON_DISPLAY_GREEN); }
void simonDisplay_eraseAllButtons() { //top left red button display_fillRect(SIMON_DISPLAY_BTN_OFFSET_X, SIMON_DISPLAY_BTN_OFFSET_Y, SIMON_DISPLAY_BUTTON_WIDTH, SIMON_DISPLAY_BUTTON_HEIGHT, SIMON_DISPLAY_BLACK); //top right yellow button display_fillRect(SIMON_DISPLAY_HALF_WIDTH + SIMON_DISPLAY_BTN_OFFSET_X, SIMON_DISPLAY_BTN_OFFSET_Y, SIMON_DISPLAY_BUTTON_WIDTH, SIMON_DISPLAY_BUTTON_HEIGHT, SIMON_DISPLAY_BLACK); //bottom left blue button display_fillRect(SIMON_DISPLAY_BTN_OFFSET_X, SIMON_DISPLAY_HALF_HEIGHT + SIMON_DISPLAY_BTN_OFFSET_Y, SIMON_DISPLAY_BUTTON_WIDTH, SIMON_DISPLAY_BUTTON_HEIGHT, SIMON_DISPLAY_BLACK); //bottom right green button display_fillRect(SIMON_DISPLAY_HALF_WIDTH + SIMON_DISPLAY_BTN_OFFSET_X, SIMON_DISPLAY_HALF_HEIGHT + SIMON_DISPLAY_BTN_OFFSET_Y, SIMON_DISPLAY_BUTTON_WIDTH, SIMON_DISPLAY_BUTTON_HEIGHT, SIMON_DISPLAY_BLACK); }
// Draws a colored "button" that the user can touch. // The colored button is centered in the region but does not fill the region. void simonDisplay_drawButton(uint8_t regionNumber) { if(regionNumber == 0)//top left region { //draw red button display_fillRect(SIMON_DISPLAY_BTN_OFFSET_X, SIMON_DISPLAY_BTN_OFFSET_Y, SIMON_DISPLAY_BUTTON_WIDTH, SIMON_DISPLAY_BUTTON_HEIGHT, SIMON_DISPLAY_RED); } else if(regionNumber == 1)//top right region { //draw yellow button display_fillRect(SIMON_DISPLAY_HALF_WIDTH + SIMON_DISPLAY_BTN_OFFSET_X, SIMON_DISPLAY_BTN_OFFSET_Y, SIMON_DISPLAY_BUTTON_WIDTH, SIMON_DISPLAY_BUTTON_HEIGHT, SIMON_DISPLAY_YELLOW); } else if(regionNumber == 2)//bottom left region { //draw blue button display_fillRect(SIMON_DISPLAY_BTN_OFFSET_X, SIMON_DISPLAY_HALF_HEIGHT + SIMON_DISPLAY_BTN_OFFSET_Y, SIMON_DISPLAY_BUTTON_WIDTH, SIMON_DISPLAY_BUTTON_HEIGHT, SIMON_DISPLAY_BLUE); } else if(regionNumber == 3)//bottom right region { //draw green button display_fillRect(SIMON_DISPLAY_HALF_WIDTH + SIMON_DISPLAY_BTN_OFFSET_X, SIMON_DISPLAY_HALF_HEIGHT + SIMON_DISPLAY_BTN_OFFSET_Y, SIMON_DISPLAY_BUTTON_WIDTH, SIMON_DISPLAY_BUTTON_HEIGHT, SIMON_DISPLAY_GREEN); } }
// Draw the game display with a background and mole holes. void wamDisplay_drawMoleBoard() { display_fillRect(0,0,DISPLAY_WIDTH, //draw a green square that doesn't cover the score strip DISPLAY_HEIGHT-(DISPLAY_CHAR_HEIGHT*WAM_D_NORMAL_TEXT), DISPLAY_GREEN); switch (currentMoleCount) { case wamDisplay_moleCount_9: for (uint8_t i = 0; i < WAM_HOLE_COUNT; i++) //iterate over rows { for (uint8_t j = 0; j <WAM_HOLE_COUNT; j++) //iterate over coumns { display_fillCircle(WAM_HOLE_FROM_LEFT+WAM_HOLE_SEPERATION_OFFSET_X*i, //intial hole spot, with row seperation WAM_HOLE_SEPERATION_OFFSET_Y*j+WAM_HOLE_FROM_TOP, //initial hole spot, with seperation WAM_HOLE_RADIUS, DISPLAY_BLACK); //hole size, color } } break; case wamDisplay_moleCount_6: for (uint8_t i = 0; i < WAM_HOLE_COUNT; i++) //iterate over rows { for (uint8_t j = 0; j <WAM_HOLE_COUNT; j++) //iterate over coumns { display_fillCircle(WAM_HOLE_FROM_LEFT+WAM_HOLE_SEPERATION_OFFSET_X*i, //intial hole spot, with row seperation WAM_HOLE_SEPERATION_OFFSET_Y*j+WAM_HOLE_FROM_TOP, //initial hole spot, with seperation WAM_HOLE_RADIUS, DISPLAY_BLACK); //hole size, color j++; //get an extra j++ so we skip the middle row } } break; case wamDisplay_moleCount_4: for (uint8_t i = 0; i < WAM_HOLE_COUNT; i++) //iterate over rows { for (uint8_t j = 0; j <WAM_HOLE_COUNT; j++) //iterate over coumns { display_fillCircle(WAM_HOLE_FROM_LEFT+WAM_HOLE_SEPERATION_OFFSET_X*i, //intial hole spot, with row seperation WAM_HOLE_SEPERATION_OFFSET_Y*j+WAM_HOLE_FROM_TOP, //initial hole spot, with seperation WAM_HOLE_RADIUS, DISPLAY_BLACK); //hole size, color j++; //get an extra j++ so we skip the middle row } i++; //extra i++ to skip middle column } break; default: printf(WAM_ERROR); break; } }
// Draws a bigger square that completely fills the region. // If the erase argument is true, it draws the square as black background to "erase" it. void simonDisplay_drawSquare(uint8_t regionNo, bool erase) { //drawing the square if(erase == false) { if(regionNo == 0) {//draw top left red square display_fillRect(0, 0, SIMON_DISPLAY_HALF_WIDTH, SIMON_DISPLAY_HALF_HEIGHT, SIMON_DISPLAY_RED); } else if(regionNo == 1) {//draw top right yellow square display_fillRect(SIMON_DISPLAY_HALF_WIDTH, 0, SIMON_DISPLAY_HALF_WIDTH, SIMON_DISPLAY_HALF_HEIGHT, SIMON_DISPLAY_YELLOW); } else if(regionNo == 2) {//draw bottom left blue square display_fillRect(0, SIMON_DISPLAY_HALF_HEIGHT, SIMON_DISPLAY_HALF_WIDTH, SIMON_DISPLAY_HALF_HEIGHT, SIMON_DISPLAY_BLUE); } else if(regionNo == 3) {//draw bottom right green square display_fillRect(SIMON_DISPLAY_HALF_WIDTH, SIMON_DISPLAY_HALF_HEIGHT, SIMON_DISPLAY_HALF_WIDTH, SIMON_DISPLAY_HALF_HEIGHT, SIMON_DISPLAY_GREEN); } } //erasing the square if(erase == true) { if(regionNo == 0) {//black out the top left square display_fillRect(0, 0, SIMON_DISPLAY_HALF_WIDTH, SIMON_DISPLAY_HALF_HEIGHT, SIMON_DISPLAY_BLACK); } else if(regionNo == 1) {//black out the top right square display_fillRect(SIMON_DISPLAY_HALF_WIDTH, 0, SIMON_DISPLAY_HALF_WIDTH, SIMON_DISPLAY_HALF_HEIGHT, SIMON_DISPLAY_BLACK); } else if(regionNo == 2) {//black out the bottom left square display_fillRect(0, SIMON_DISPLAY_HALF_HEIGHT, SIMON_DISPLAY_HALF_WIDTH, SIMON_DISPLAY_HALF_HEIGHT, SIMON_DISPLAY_BLACK); } else if(regionNo == 3) {//black out the bottom right square display_fillRect(SIMON_DISPLAY_HALF_WIDTH, SIMON_DISPLAY_HALF_HEIGHT, SIMON_DISPLAY_HALF_WIDTH, SIMON_DISPLAY_HALF_HEIGHT, SIMON_DISPLAY_BLACK); } } }
void simonDisplay_drawButton(uint8_t regionNumber) { // Set the values of the sub box dimensions uint16_t x_max = display_width(); uint16_t y_max = display_height(); // Compute dimensions of the 4 sub regions uint16_t box_width = GLOBALS_ONE_HALF(x_max); uint16_t box_height = GLOBALS_ONE_HALF(y_max); // Compute dimensions of half the button sizes for convenience in drawing uint16_t button_half_width = GLOBALS_ONE_HALF(SIMON_DISPLAY_BUTTON_WIDTH); uint16_t button_half_height = GLOBALS_ONE_HALF(SIMON_DISPLAY_BUTTON_HEIGHT); // Variables to be used in computing the centerpoint of each subregion uint16_t origin_x, origin_y; // The dimensions of the button is define by the header file switch (regionNumber) { case SIMON_DISPLAY_REGION_0: // Compute the origin point of the box origin_x = GLOBALS_ONE_HALF(box_width) - button_half_width; origin_y = GLOBALS_ONE_HALF(box_height) - button_half_height; // Draw the RED square display_fillRect( origin_x, // x0 origin_y, // y0 SIMON_DISPLAY_BUTTON_WIDTH, // width SIMON_DISPLAY_BUTTON_HEIGHT, // height DISPLAY_RED // color ); break; case SIMON_DISPLAY_REGION_1: // Compute the origin point of the box origin_x = box_width; origin_y = 0; origin_x = GLOBALS_ONE_HALF(box_width) - button_half_width + origin_x; origin_y = GLOBALS_ONE_HALF(box_height) - button_half_height + origin_y; // Draw the YELLOW square display_fillRect( origin_x, // x0 origin_y, // y0 SIMON_DISPLAY_BUTTON_WIDTH, // width SIMON_DISPLAY_BUTTON_HEIGHT, // height DISPLAY_YELLOW // color ); break; case SIMON_DISPLAY_REGION_2: // Compute the origin point of the box origin_x = 0; origin_y = box_height; origin_x = GLOBALS_ONE_HALF(box_width) - button_half_width + origin_x; origin_y = GLOBALS_ONE_HALF(box_height) - button_half_height + origin_y; // Draw the BLUE square display_fillRect( origin_x, // x0 origin_y, // y0 SIMON_DISPLAY_BUTTON_WIDTH, // width SIMON_DISPLAY_BUTTON_HEIGHT, // height DISPLAY_BLUE // color ); break; case SIMON_DISPLAY_REGION_3: // Compute the origin point of the box origin_x = box_width; origin_y = box_height; origin_x = GLOBALS_ONE_HALF(box_width) - button_half_width + origin_x; origin_y = GLOBALS_ONE_HALF(box_height) - button_half_height + origin_y; // Draw the GREEN square display_fillRect( origin_x, // x0 origin_y, // y0 SIMON_DISPLAY_BUTTON_WIDTH, // width SIMON_DISPLAY_BUTTON_HEIGHT, // height DISPLAY_GREEN // color ); break; default: printf("Draw button default case hit\n"); // shouldn't hit this break; } }
void simonDisplay_drawSquare(uint8_t regionNo, bool erase) { // Set the values of the sub box dimensions uint16_t x_max = display_width(); uint16_t y_max = display_height(); // Compute dimensions of the 4 sub regions uint16_t box_width = GLOBALS_ONE_HALF(x_max); uint16_t box_height = GLOBALS_ONE_HALF(y_max); // Variables to be used in computing the centerpoint of each subregion uint16_t origin_x, origin_y; // The dimensions of the button is define by the header file switch (regionNo) { case SIMON_DISPLAY_REGION_0: // Compute the origin point of the box origin_x = 0; origin_y = 0; if (erase) { // Draw BLACK to erase the square display_fillRect( origin_x, // x0 origin_y, // y0 box_width, // width box_height, // height DISPLAY_BLACK // color ); } else { // Draw the RED square display_fillRect( origin_x, // x0 origin_y, // y0 box_width, // width box_height, // height DISPLAY_RED // color ); } break; case SIMON_DISPLAY_REGION_1: // Compute the origin point of the box origin_x = box_width; origin_y = 0; if (erase) { // Draw BLACK to erase the square display_fillRect( origin_x, // x0 origin_y, // y0 box_width, // width box_height, // height DISPLAY_BLACK // color ); } else { // Draw the YELLOW square display_fillRect( origin_x, // x0 origin_y, // y0 box_width, // width box_height, // height DISPLAY_YELLOW // color ); } break; case SIMON_DISPLAY_REGION_2: // Compute the origin point of the box origin_x = 0; origin_y = box_height; if (erase) { // Draw BLACK to erase the square display_fillRect( origin_x, // x0 origin_y, // y0 box_width, // width box_height, // height DISPLAY_BLACK // color ); } else { // Draw the BLUE square display_fillRect( origin_x, // x0 origin_y, // y0 box_width, // width box_height, // height DISPLAY_BLUE // color ); } break; case SIMON_DISPLAY_REGION_3: // Compute the origin point of the box origin_x = box_width; origin_y = box_height; if (erase) { // Draw BLACK to erase the square display_fillRect( origin_x, // x0 origin_y, // y0 box_width, // width box_height, // height DISPLAY_BLACK // color ); } else { // Draw the GREEN square display_fillRect( origin_x, // x0 origin_y, // y0 box_width, // width box_height, // height DISPLAY_GREEN // color ); } break; default: printf("Draw square default case hit\n"); // shouldn't hit this break; } }
// Helper function to write data to the LCD based on what button is pressed, // blanks the screen otherwise. void buttons_write_LCD(int32_t buttons) { // If BTN 0 is pressed if (buttons & BUTTONS_BTN0_MASK) { // check if btn0 is set so image is only drawn once if (btn0_status == BUTTONS_NOT_SET) { // Draw the background colored rectangle display_fillRect(x_three_fourths, 0, x_fourth, y_max, DISPLAY_CYAN); // Print BTN text in the middle of the rectangle display_setCursor(x_three_fourths, y_half); // position cursor display_println(" BTN 0"); // Mark the button as SET so that there is no flickering of the image btn0_status = BUTTONS_SET; } } else { // Blank the used portion of the screen display_fillRect(x_three_fourths, 0, x_fourth, y_max, DISPLAY_BLACK); btn0_status = BUTTONS_NOT_SET; // mark btn0 as not set } // If BTN 1 is pressed if (buttons & BUTTONS_BTN1_MASK) { // Only draw image once if (btn1_status == BUTTONS_NOT_SET) { // Draw the background colored rectangle display_fillRect(x_half, 0, x_fourth, y_max, DISPLAY_YELLOW); // Print BTN text in the middle of the rectangle display_setCursor(x_half, y_half); // position the cursor display_println(" BTN 1"); // Mark the button as SET to eliminate flickering btn1_status = BUTTONS_SET; } } else { // Blank the used portion of the screen display_fillRect(x_half, 0, x_fourth, y_max, DISPLAY_BLACK); btn1_status = BUTTONS_NOT_SET; } // If BTN 2 is pressed if (buttons & BUTTONS_BTN2_MASK) { // Only draw image once if (btn2_status == BUTTONS_NOT_SET) { // Draw the background colored rectangle display_fillRect(x_fourth, 0, x_fourth, y_max, DISPLAY_GREEN); // Print BTN text in the middle of the rectangle display_setCursor(x_fourth, y_half); // Position the cursor display_println(" BTN 2"); // Mark the button as SET to eliminate flickering btn2_status = BUTTONS_SET; } } else { // Blank the used portion of the screen display_fillRect(x_fourth, 0, x_fourth, y_max, DISPLAY_BLACK); btn2_status = BUTTONS_NOT_SET; } // If BTN 3 is pressed if (buttons & BUTTONS_BTN3_MASK) { // Only draw image once if (btn3_status == BUTTONS_NOT_SET) { // Draw the background colored rectangle display_fillRect(0, 0, x_fourth, y_max, DISPLAY_RED); // Print BTN text in the middle of the rectangle display_setCursor(0, y_half); // set cursor to middle of rect display_println(" BTN 3"); // Mark the button as SET to eliminate flickering btn3_status = BUTTONS_SET; // mark btn3 as set } } else { // Blank the used portion of the screen display_fillRect(0, 0, x_fourth, y_max, DISPLAY_BLACK); btn3_status = BUTTONS_NOT_SET; } }
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); }