void game_end() { //turns off all communication with Node2 timer_disable(); //can_play_music(); oled_clear_screen(); //print GAME OVER oled_pos(3, 4); oled_printf("GAME OVER"); _delay_ms(1500); oled_clear_screen(); oled_pos(2, 2); oled_printf("Final score:"); oled_pos(4, 7); oled_printf("%d", game_score); printf("Final score: %d\n", game_score); oled_pos(7, 0); oled_printf("press any button"); while ((!button_read(2) && !button_read(1) && button_read(3)) ); //wait for button press _delay_ms(100); oled_clear_screen(); }
//Initializes the OLED screen with a blank screen void oled_init(){ write_c(0xae); // display off write_c(0xa1); //segment remap write_c(0xda); //common pads hardware: alternative write_c(0x12); write_c(0xc8); //common output scan direction:com63~com0 write_c(0xa8); //multiplex ration mode:63 write_c(0x3f); write_c(0xd5); //display divide ratio/osc. freq. mode write_c(0x80); write_c(0x81); //contrast control write_c(0x50); write_c(0xd9); //set pre-charge period write_c(0x21); write_c(0x20); //Set Memory Addressing Mode write_c(0x02); write_c(0xdb); //VCOM deselect level mode write_c(0x30); write_c(0xad); //master configuration write_c(0x00); write_c(0xa4); //out follows RAM content write_c(0xa6); //set normal display write_c(0xaf); // display on // Clear screen oled_clear_screen(); }
void oled_welcome(){ oled_clear_screen(); char message1[] = "VELKOMMEN!"; char message2[] = "WELCOME!"; char message3[] = "Willkommen!"; char message4[] = "Bienvenue!"; char message5[] = "Bon bini!"; char message6[] = "Mauya!"; char message7[] = "Welkam!"; oled_goto_line(0); oled_print(message1); oled_goto_line(1); oled_print(message2); oled_goto_line(2); oled_print(message3); oled_goto_line(3); oled_print(message4); oled_goto_line(4); oled_print(message5); oled_goto_line(5); oled_print(message6); oled_goto_line(6); oled_print(message7); _delay_ms(1000); }
void Task4() { uint16_t cnt; uint8_t v; uint8_t row; printf( "Task4 PID=%u\r\n",nrk_get_pid()); oled_on(); cnt=0; row=0; while(1) { v=hrm_get_value(); sprintf(txt_str,"%d%d%d cnt=%d hrm=%d",nrk_gpio_get(NRK_MMC_9), nrk_gpio_get(NRK_MMC_10), nrk_gpio_get(NRK_MMC_11), cnt,v); oled_write_str( 2, row, 0, 0xFFFF, txt_str ); /* oled_clear_screen(); nrk_wait_until_ticks(50); sprintf(txt_str,"Neighbor List:"); oled_write_str( 2, 3, 0, 0xFFFF, txt_str ); nrk_wait_until_ticks(50); sprintf(txt_str," 0x100002a -27 4"); oled_write_str( 2, 4, 0, 0xFFFF, txt_str ); nrk_wait_until_ticks(50); sprintf(txt_str," 0x1000012: -30 2"); oled_write_str( 2, 5, 0, 0xFFFF, txt_str ); nrk_wait_until_ticks(50); sprintf(txt_str," 0x100000a: -5 3"); oled_write_str( 2, 6, 0, 0xFFFF, txt_str ); nrk_wait_until_ticks(50); sprintf(txt_str,"Round Trip Pkt: 93%%"); oled_write_str( 2, 9, 0, 0xFFFF, txt_str ); nrk_wait_until_ticks(50); //putc0(0x70); //putc0(0x01); //nrk_wait_until_ticks(50); oled_draw_square( 8, 83, 150, 92, 0x001F ); nrk_wait_until_ticks(50); //putc0(0x70); //putc0(0x00); //nrk_wait_until_ticks(50); oled_draw_square( 10, 85, 100, 90, 0x07e0 ); nrk_wait_until_ticks(50); */ cnt++; row++; if(row==15) { oled_clear_screen(); row=0; } nrk_wait_until_next_period(); } }
void snake_print(int8_t snake[MAX_LENGTH][3]){ oled_clear_screen(); for (uint8_t i = 0; i < slength; i++){ oled_put_string(snake[i][pos_x]*8, abs(snake[i][pos_y] - 7), "O"); } if(apple[2]){ oled_put_string(apple[0] * 8, abs(apple[1] - 7), "Q"); } oled_write_screen(); }
void snake_game_over(){ oled_clear_screen(); oled_put_string(3*8, 0, "GAME OVER"); /*oled_put_string(0*8, 5, "Score:");*/ oled_write_screen(); while(1){ if(button_left_read()){ return; } } }
void oled_game_over(){ oled_clear_screen(); sound_play(GAMEOVER); //Play game over music char message1[] = "GAME OVER"; //char message2[] = "YOU DIED"; oled_goto_line(3); oled_changeColumn(2); oled_print(message1); _delay_ms(3000); sound_play(SILENCE); //prevent looping _delay_ms(1000); }
void game_introMessage(void) { oled_clear_screen(); oled_set_write_position(0, 0); oled_printf("Welcome to this"); oled_set_write_position(1, 0); oled_printf("interactive ball"); oled_set_write_position(2, 0); oled_printf("bump experience."); oled_set_write_position(4, 0); oled_printf("Put your balls"); oled_set_write_position(5, 0); oled_printf("on the solenoid"); oled_set_write_position(6, 0); oled_printf("to begin.."); oled_set_write_position(7, 0); oled_printf(" ..good luck"); }
void game_end(void) { timer_disable(); oled_clear_screen(); uint8_t rank = highscore_update(game_score); if(rank) { game_postGameMessage(rank); _delay_ms(5000); } else { oled_set_write_position(2, 8); printf("You so bad."); _delay_ms(5000); } highscore_print(); }
void snake_settings(){ uint8_t difficulty; while(1){ difficulty = slider_right_read(); if(timer_read(TIMER_3) > 1000){ oled_clear_screen(); oled_put_string(0*8, 0, "Set difficulty"); oled_put_string(0, 1, "Difficulty:%u", difficulty); oled_put_string(0, 3, "Walls"); if(no_walls){ oled_put_string(7*8,3,"OFF"); } else{ oled_put_string(7*8,3,"ON"); } oled_write_screen(); if(button_right_read()){ if(no_walls){ no_walls = 0; } else{ no_walls = 1; } } timer_reset(TIMER_3); } if(button_left_read()){ if(difficulty < 1){ s_difficulty = 1; } s_difficulty = difficulty / 4; return; } } }
void game_start() { game_reset_score(); game_not_lost = 1; /* oled_clear_screen(); oled_pos(3,2); oled_printf("remove ball"); _delay_ms(1500);*/ oled_clear_screen(); oled_pos(3, 2); oled_printf("Score: "); //flush pending game_lost messages can_data_receive(); can_data_receive(); timer_enable(); ball_rolling = 0; }
void game_start(void) { game_lost = 0; timer_enable(); game_reset_score(); oled_clear_screen(); }
void oled_submenu2(){ volatile position joy_pos; joy_pos.button_pressed = 150; oled_clear_screen(); /*FIRST MENU*/ // header char header[] = "YOU ARE TRAPPED!"; // entry one char entry1[] = "NEVER"; // entry two char entry2[] = "GONNA"; // entry three char entry3[] = "GIVE YOU UP"; // arrow starts on entry one. Movement of joystick along Y axis changes this int arrow = menu_entry_one; int prev_arrow; int navigation_counter = 999; int started = 0; //Define menu pointer oled_pos(menu_entry_one, arrow_column); oled_print("<<"); sound_play(ROLL); while(!started){ oled_goto_line(menu_header); oled_print(header); oled_goto_line(menu_entry_one); oled_print(entry1); oled_goto_line(menu_entry_two); oled_print(entry2); oled_goto_line(menu_entry_three); oled_print(entry3); if(joystickDirY() != NEUTRAL){ navigation_counter++; } else{ navigation_counter = 1; } if(navigation_counter % 100 == 0){ prev_arrow = arrow; if(joystickDirY() == UP){ if(arrow == menu_entry_one){ arrow = menu_entry_three; } else{ arrow--; } } else if(joystickDirY() == DOWN){ if(arrow == menu_entry_three){ arrow = menu_entry_one; } else{ arrow++; } } oled_goto_line(prev_arrow); oled_clear_line(); oled_goto_line(arrow); oled_changeColumn(arrow_column); oled_print("<<"); oled_changeColumn(0); navigation_counter++; } //Handle button presses joy_pos = joystickPos(); if(joy_pos.button_pressed < button_margin){ while(joy_pos.button_pressed < button_margin){ //Prevent button spam joy_pos = joystickPos(); } started = 1; button_pressed = 0; } } return 0; }
int oled_submenu1(){ volatile position joy_pos; joy_pos.button_pressed = 150; oled_clear_screen(); /*FIRST MENU*/ // header char header[] = "MUSIC MENU"; // entry one char entry1[] = "POKEMON"; // entry two char entry2[] = "SUPER MARIO"; // entry three char entry3[] = "ZELDA"; // arrow starts on entry one. Movement of joystick along Y axis changes this int arrow = menu_entry_one; int prev_arrow; int navigation_counter = 999; int started = 0; //Define menu pointer oled_pos(menu_entry_one, arrow_column); oled_print("<<"); sound_play(POKEMON); while(!started){ oled_goto_line(menu_header); oled_print(header); oled_goto_line(menu_entry_one); oled_print(entry1); oled_goto_line(menu_entry_two); oled_print(entry2); oled_goto_line(menu_entry_three); oled_print(entry3); if(joystickDirY() != NEUTRAL){ navigation_counter++; } else{ navigation_counter = 1; } if(navigation_counter % 100 == 0){ prev_arrow = arrow; if(joystickDirY() == UP){ if(arrow == menu_entry_one){ arrow = menu_entry_three; } else{ arrow--; } } else if(joystickDirY() == DOWN){ if(arrow == menu_entry_three){ arrow = menu_entry_one; } else{ arrow++; } } //Let user listen to currently selected song if(arrow == menu_entry_one){ sound_play(POKEMON); } else if(arrow == menu_entry_two){ sound_play(MARIO); } else if(arrow == menu_entry_three){ sound_play(ZELDA); } else { sound_play(ROLL); } oled_goto_line(prev_arrow); oled_clear_line(); oled_goto_line(arrow); oled_changeColumn(arrow_column); oled_print("<<"); oled_changeColumn(0); navigation_counter++; } //Handle button presses joy_pos = joystickPos(); if(joy_pos.button_pressed < button_margin){ while(joy_pos.button_pressed < button_margin){ //Prevent button spam joy_pos = joystickPos(); } if(arrow == menu_entry_one){ ingame_song = POKEMON; } else if(arrow == menu_entry_two){ ingame_song = MARIO; } else if(arrow == menu_entry_three){ ingame_song = ZELDA; } started = 1; button_pressed = 0; } } return 0; }
int oled_navigate(){ volatile position joy_pos; joy_pos.button_pressed = 150; oled_clear_screen(); /*FIRST MENU*/ // header char header[] = "MENU"; // entry one char entry1[] = "Start game"; // entry two char entry2[] = "Change music"; // entry three char entry3[] = "DO NOT PRESS!"; // arrow starts on entry one. Movement of joystick along Y axis changes this int arrow = menu_entry_one; int prev_arrow; int navigation_counter = 999; int started = 0; //Define menu pointer oled_pos(menu_entry_one, arrow_column); oled_print("<<"); sound_play(MENU); while(!started){ oled_goto_line(menu_header); oled_print(header); oled_goto_line(menu_entry_one); oled_print(entry1); oled_goto_line(menu_entry_two); oled_print(entry2); oled_goto_line(menu_entry_three); oled_print(entry3); if(joystickDirY() != NEUTRAL){ navigation_counter++; } else{ navigation_counter = 1; } if(navigation_counter % 100 == 0){ prev_arrow = arrow; if(joystickDirY() == UP){ if(arrow == menu_entry_one){ arrow = menu_entry_three; } else{ arrow--; } } else if(joystickDirY() == DOWN){ if(arrow == menu_entry_three){ arrow = menu_entry_one; } else{ arrow++; } } oled_goto_line(prev_arrow); oled_clear_line(); oled_goto_line(arrow); oled_changeColumn(arrow_column); oled_print("<<"); oled_changeColumn(0); navigation_counter++; } //Handle button presses joy_pos = joystickPos(); if(joy_pos.button_pressed < button_margin){ while(joy_pos.button_pressed < button_margin){ //Prevent button spam joy_pos = joystickPos(); } if(arrow == menu_entry_one){ started = 1; //A game request has been received, so we should stop interfacing } else if(arrow == menu_entry_two){ oled_submenu1(); oled_clear_screen(); //Redefine menu pointer oled_goto_line(arrow); oled_changeColumn(arrow_column); oled_print("<<"); oled_changeColumn(0); sound_play(MENU); } else if(arrow == menu_entry_three){ oled_submenu2(); oled_clear_screen(); //Redefine menu pointer oled_goto_line(arrow); oled_changeColumn(arrow_column); oled_print("<<"); oled_changeColumn(0); sound_play(MENU); } button_pressed = 0; } } return 0; }