//#include //#include // Arduino LCD library //#include // colors for set_color function #define ST7735_RED 5 #define ST7735_BLUE 4 #define ST7735_YELLOW 3 #define ST7735_GREEN 2 #define ST7735_WHITE 1 #define ST7735_BLACK 0 #define SPACE_CHARACTER 32 #define HALF_WAY_INDEX_TABLE_1 13 #define HALF_WAY_INDEX_TABLE_2 13 #define MAX_ENTRIES_INDEX_TABLE_1 (7+1) // number of search entries in search table #define MAX_ENTRIES_INDEX_TABLE_2 (7+1) // number of search entries in search table #define QUEST_ENTRY_INDEX_TABLE_1 15 #define QUEST_ENTRY_INDEX_TABLE_2 6 // These definitions map display functions to the Adduino Esplora display header pins #define sclk 15 #define mosi 16 #define cs 7 #define dc 0 #define rst 1 #define NUMBER_ITEM_SUPPORTED 3 unsigned char ship_type [] = {1,2,3}; unsigned char ship_location[NUMBER_ITEM_SUPPORTED]; // current strting location of a given item unsigned char ship_state[NUMBER_ITEM_SUPPORTED]; // current logic state of the item. int tick_marks; void simulate_poke(char xLocation, char yLocation, unsigned char symbol_char, boolean shp_type) { Serial.print("simulate_poke(): xLocation="); Serial.print(xLocation,DEC); Serial.print(", yLocation="); Serial.print(yLocation,DEC); Serial.print(", symbol_char="); Serial.print(symbol_char); Serial.print(", ship_type="); Serial.println(shp_type); } void erase_symbol_cells_from_screen(char xLocation, char yLocation) { Serial.print("erase_symbol_cells_from_screen(): xLocation="); Serial.print(xLocation,DEC); Serial.print(", yLocation="); Serial.println(yLocation,DEC); } void update_ship_movement(void) { Serial.print("update_ship_movement(): "); int shp_state; int shp_type; unsigned char j; for (unsigned char i = 0; i < NUMBER_ITEM_SUPPORTED; i++) // updates each active symbols/Ships for this tickmark of time { // j = ship_location[i]; Serial.print("ship_type[0] = "); Serial.print(ship_type[0]); Serial.print(", ship_type[1] = "); Serial.print(ship_type[1]); Serial.print(", ship_type[2] = "); Serial.print(ship_type[2]); Serial.print(", i = "); Serial.print(i,DEC); // shp_type = (int) ship_type[i]; // shp_state = (int) ship_state[i]; Serial.print(", shp_type = "); Serial.print(shp_type); Serial.print(", shp_state = "); Serial.println(shp_state); // int old_state = shp_state; // // switch (shp_type) { // // case 1: // Destroyer // // if ((shp_state == 1) or (shp_state == 3)) // { // simulate_poke(j, 1, 181, 1); // simulate_poke(j+1, 1, 180, 1); // ++shp_state; //advance logic state for a given symbol or ship // } // else if ((shp_state == 2) or (shp_state == 4)) // { // erase_symbol_cells_from_screen(j,1); // erase_symbol_cells_from_screen(j+1,1); // ++j; // advance ship location // ++shp_state; //advance logic state for a given symbol or ship // } // // break; // // case 2: // cruiser // // if ((shp_state == 1) or (shp_state == 3)) // { // ++shp_state; //advance logic state for a given symbol or sh // } // else if (shp_state == 2) // { // simulate_poke(j,5, 185, 1); // simulate_poke(j+1,5, 186, 1); // simulate_poke(j+2,5, 183, 1); // ++shp_state; //advance logic state for a given symbol or ship // } // else if (shp_state == 4) // { // erase_symbol_cells_from_screen(j,5); // erase_symbol_cells_from_screen(j+1,5); // erase_symbol_cells_from_screen(j+2,5); // ++shp_state; //advance logic state for a given symbol or ship // ++j; // adavance current location by 1 // } // else // { // } // // break; // // case 3: // if ((shp_state == 1) or (shp_state == 3)) // { // ++shp_state; //advance logic state for a given symbol or sh // } // else if (shp_state == 2) // { simulate_poke(j, 3, 217, 1); // simulate_poke(j+1, 3, 218, 1); // simulate_poke(j+2, 3, 221, 1); // simulate_poke(j+3, 3, 220, 1); // simulate_poke(j+4, 3, 219, 1); // ++shp_state; //advance logic state for a given symbol or ship // } // else if (shp_state == 4) // { // erase_symbol_cells_from_screen(j,3); // erase_symbol_cells_from_screen(j+1,3); // erase_symbol_cells_from_screen(j+2,3); // erase_symbol_cells_from_screen(j+3,3); // erase_symbol_cells_from_screen(j+4,3); // ++shp_state; //advance logic state for a given symbol or ship // ++j; // adavance current location by 1 // } // else // { // } // // break; // // default: // logic state like 0 .. just do nothing at this time // break; // // } // end of logic state switch // // if (old_state != shp_state) // { // if (j == 16) // { // check if ship/symbol has gone pass the screen on the right. // shp_state = 0; //disable symbol that went off the screen // j = 1; //re-define location back 1 when need to be used again // // } // else { // if (shp_state == 5) // { // shp_state = 1; // re-start ship/symbol state back to 1 again - we assume ship or sybol has gone passed end of LCD screen // } // } // // ship_state[i] = (unsigned char) shp_state; // update ship's state // ship_location[i] = j; // update ship's location // } // // delay(10); // // break; // debug } // end for loop } // end of function update_ship_movement void setup() { // put your setup code here, to run once: Serial.begin(115200); //EsploraTFT.begin(); //EsploraTFT.background(0, 0, 0); for (unsigned char i=0; i < NUMBER_ITEM_SUPPORTED; i++) { ship_location[i] = 1; ship_state[i] = 0; // disabled state for a given symbol } tick_marks = 0; ship_state[0] = 1; // enable destroyer type } void loop() { // put your main code here, to run repeatedly: update_ship_movement(); delay(16); delay(1000); ++tick_marks; // if (tick_marks == 120) // ship_state[1] = 1; }