/*Ici les fantomes accélèrent de plus en plus * et le but est de tenir le plus longtemps * sans se faire dévorer*/ void survivor(int level, config *cfg) { if(level>=NB_LEVEL) return; int selection, counter=SDL_GetTicks(), tmp=counter, elapsed; SAVE_ENABLE=0; play_menu(level); Pacman pac; Fantome ftm[NB_MAX_GHOSTS]; score_message *msg_list = NULL; Input in; init_pacman(&pac, cfg); init_level(); init_blocks(); load_level(level); pac_restart(&pac); pac.nb_lives=1; init_ghosts(ftm, cfg); memset(&in,0,sizeof(in)); DELAY = 40; while(pac.nb_lives && POINTS) { elapsed = SDL_GetTicks()-tmp; if(elapsed > 10000) { //On accélere les fantomes speed_up(ftm, 1); tmp=SDL_GetTicks(); } UpdateEvents(&in); if(in.quit) //Si clique sur croix { delete(&pac, ftm); exit(EXIT_SUCCESS); } while(in.key[SDLK_ESCAPE]) { selection=game_menu(); if(selection==0) in.key[SDLK_ESCAPE]=0; else if(selection==2) //Retour menu principal { delete(&pac, ftm); return; } } jouer(&pac, ftm, in, cfg, level, &msg_list); } counter = SDL_GetTicks() - counter; fprintf(stderr, "Wouaw tu as tenu %d ms!\n", counter); if(pacmanIsHuman(cfg)) draw_result("data/survivor.txt", counter); delete(&pac, ftm); }
//////////////////////////////////////////////// //BOT CONTROL void bot_control(void) { //S0 if(SH_LEFT>=125 && SH_LEFT<=140) { S4_t=0; //for S4 CURR_S=S0; if(!S3_t) set_servo(CENTER); if(SH_CENTER<70 && SH_CENTER>=55) {speed_down(4);goto f_exit;} else if(SH_CENTER>=70) {S3_t=1;speed_down(4);set_servo(MAX_RIGHT);goto f_exit;} else if(SH_CENTER<55) {S3_t=0;speed_up(5);goto f_exit;} } //S1 else if(SH_LEFT>140 && SH_LEFT<=240) { S4_t=0; //for S4 CURR_S=S1; //------------------- if(SH_CENTER>=70) { S3_t=1; //for S3 speed_down(4); set_servo(MAX_RIGHT); goto f_exit; } else { S3_t=0; set_servo(MIN_RIGHT); speed_down(2); } //------------------- goto f_exit; } //S2 else if(SH_LEFT>240 || S3_t) { S4_t=0; //for S4 CURR_S=S2; //------------------- set_servo(MAX_RIGHT); speed_down(5); //------------------- goto f_exit; } //S3 else if(SH_LEFT<125 && SH_LEFT>=100 && !S3_t) { S4_t=0; //for S4 CURR_S=S3; //------------------- set_servo(MIN_LEFT); speed_down(3); //------------------- goto f_exit; } //S4 else if(SH_LEFT<100) { S3_t=0; //------------------- switch(S4_t) { case 0: { S4_t=1; CURR_S=S40; speed_down(3); set_servo(MIN_LEFT); delay_ms(10); break; }; case 1: { CURR_S=S41; speed_down(1); set_servo(MAX_LEFT); break; }; }; //------------------- goto f_exit; } f_exit: #asm nop #endasm };
void on_button8_clicked (GtkButton *button, gpointer user_data) { speed_up(); }
int main(void) { // open the Character LCD port char_lcd_dev = alt_up_character_lcd_open_dev ("/dev/LCD"); /* Initialize the character display */ alt_up_character_lcd_init(char_lcd_dev); // Initially writes the start time of timer to lcd write_time_to_buffer(top_row, seconds, minutes, hours, am_pm_mode); hex_write_date(month, day, year); // Initialize the switches int * sw_ptr = (int *) SW_BASE; int sw_values; int oldvalue = 0x00000000; // Masks for individual switches int MASK_17 = 0x00020000; int MASK_16 = 0x00010000; int MASK_1 = 0x00000002; int MASK_0 = 0x00000001; int is_fast = 0; //use to tell other function if sped up, 0 = slow, 1 = fast int clk_modify = 0; //if 0, clock isn't being changed, if 1 clock is being changed int alarm_modify = 0; //if 0 alarm isn't being changed, if 1, alarm is being changed // Initialize the Timers init_timer_0(&tenths); // Tracker to see when the time changes int old_tenths = 0; // Initialize the KEY port init_button_pio(); // continually while(1) { // check the state of the context integer updated by various ISR functions // Act accordingly, which means // Update the switch_values sw_values = *(sw_ptr); //check if sw17 is up and if it is, then speed up the timer if((sw_values & MASK_17) == 0x00020000 && oldvalue == 0x00000000){ speed_up(); oldvalue = sw_values & MASK_17; is_fast = 1; } //check if sw17 is down and if it is then slow down the timer else if ((sw_values & MASK_17) == 0x00000000 && oldvalue == 0x00020000) { slow_down(); oldvalue = sw_values & MASK_17; is_fast = 0; } // Allow user to change the time if SW0 is up if((sw_values & MASK_0) == 0x00000001){ clk_modify = 1; } else{ clk_modify = 0; } // Buttons increment the hours, minutes, and seconds, respectively to Key3, Key2, and Key1 if(clk_modify == 1 && alarm_modify == 0 && alarm == 0){ // Handle if a key was pressed if (edge_capture) { handle_key_press_time(); } } // Allow user to change the alarm if SW1 is up if((sw_values & MASK_1) == 0x00000002){ alarm_modify = 1; alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1); alt_up_character_lcd_string(char_lcd_dev, bot_row); } else{ alarm_modify = 0; alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1); alt_up_character_lcd_string(char_lcd_dev, " "); } // Buttons increment the hours, minutes, and seconds, respectively to Key3, Key2, and Key1 if(alarm_modify == 1 && clk_modify == 0 && alarm == 0){ // Handle if a key was pressed if (edge_capture) { handle_key_press_alarm_set(); } } // Check if alarm should go off yet if(hours == alarm_hours && minutes == alarm_minutes && seconds == 0){ alarm = 1; init_timer_1(&half_second); } // While alarm is going off if( alarm == 1 ){ if (half_second % 2) { // Turn hex on hex_on(); } else { // Turn hex off hex_off(); } if( edge_capture) { handle_key_press_alarm(); } } else { stop_timer_1(); } // Check SW16 for "AM_PM" enable or "24" mode enable // If the switch is enabled, then we turn on 24 hour mode // Else we turn on AM / PM Mode // TODO: Optimize so that it doesn't assign something every loop cycle. Maybe we could slim it down if((sw_values & MASK_16) == MASK_16 ) { am_pm_mode = 0; } else { am_pm_mode = 1; } // Update the clock if (tenths != old_tenths) { // Call the util.h function to update the time update_time(top_row, &old_tenths, &tenths, &seconds, &minutes, &hours, &day, &month, &year, am_pm_mode, 0); // Write the updated time to the display alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 0); alt_up_character_lcd_string(char_lcd_dev, top_row); } } return 0; }
int main(void) //beginning of main function { DDRA=asmfunction(); //set PORTA to write DDRB=0xFF; //set PORTB to write DDRC=0xFF; //set PORTC to write DDRD=0b10111011; //set PIND2 and PIND6 to read and the rest of PORTD to write PORTB=PORTB&0b01111111; //set PINB7 to logic zero (turn on green LED) PORTB=PORTB|0b01000000; //set PINB6 to logic one (turn off red LED) PORTD=0b01000100; //enable pull-up resistors of PIND2 and PIND6 lcd_init(); //initialize LCD display lcd_clear(); //clear LCD display lcd_home(); //set cursor of LCD to the first character position /*The next two lines configure T/C0 and T/C2 to set OCR0 and OCR2, respectively on compare match when the T/C subsystem's respective counting register is counting up and to clear OCR0 and OCR2 when counting down. Configured as Fast PWM, Phase-Correct with a prescalar of one.*/ TCCR2=(1<<WGM20)|(1<<COM21)|(1<<COM20)|(1<<CS20); TCCR0=(1<<WGM00)|(1<<COM01)|(1<<COM00)|(1<<CS00); /*The next two lines configure TCNT1 to increment every clock cycle; Configure Enable Input Capture Interrupt to trigger on rising edge; Enable Input Capture Noise Canceller; Locally enable T/C 1 Input Capture Interrupt and T/C 1 Overflow Interrupt.*/ TCCR1B=(1<<ICES1)|(1<<CS10)|(1<<ICNC1); TIMSK=(1<<TICIE1)|(1<<TOIE1); MCUCR=(1<<ISC00)|(1<<ISC01);//configure external interrupt 1 to trigger on rising edge GICR=(1<<INT0); //locally enable external interrupt 1 sei(); //set global interrupt flag unsigned long int button=0; //unsigned long integer (32 bits--sent by IR remote) uint8_t led=0; //state of LED (used to confirm 34-bit transmission by IR remote) int speed=0; //speed of motors at maximum int lights=off; lcd_printf("Waiting"); //print "Waiting" on LCD (wait for button to be pushed on IR remote) PORTB=PORTB|0b00000010; while(1) //infinite loop { if(bit==34) //wait until bit=34--Input Capture ISR called 34 times (1 start bit, 32 data bits, and 1 stop bit sent by IR remote) { button=decipher(remote); //decipher the 32 data bits as either 1 or 0 depending on TCNT1 values; //pass remote as parameter and set button equal to return value bit=0; //reset bit equal to 0 (prepare to receive a new command) if(led==0) //if the state of led is 0, turn off green LED and turn on red LED { //then switch the state of led to 1 PORTB=PORTB&0b10111111; PORTB=PORTB|0b10000000; led++; } else //if the state of led is not 0 (state is 1), turn off red LED and turn on green LED { //then switch the state of led to 0 PORTB=PORTB&0b01111111; PORTB=PORTB|0b01000000; led--; } switch(button) //check the value of button (button that was pushed on remote) { case up_arrow: //if up arrow was pushed, make robot go forward forward(); break; case down_arrow: //if down arrow was pushed, make robot go backward backward(); break; case left_arrow: //if left arrow was pushed, make robot go left left(); break; case right_arrow: //if right arrow was pushed, make robot go right right(); break; case channel_up: //if channel up was pushed, speed robot up (speed is parameter sent to speed_up function); speed equals returned value speed=speed_up(speed); break; case channel_down: //if channel down was pushed, slow robot down (speed is parameter sent to speed_down function); speed equals returned value speed=slow_down(speed); break; case mute: //if mute was pushed, toggle lights from off to on or on to off; pass lights as parameter and set lights equal to returned value lights=toggle_lights(lights); break; default: //if any other button was pushed, stop robot stop(); break; } OCR0=speed; //set the speed of the left motor depending on value of speed OCR2=speed; //set the speed of the right motor depending on value of speed } } }