/* com os 40ms para fazer 3min sa presisos 4500ciclos */ void TimeOut(){ //int tempo=readCoreTimer(); ciclos++; //printf("read %d \n", ciclos); if(ciclos>=4500){ //falta ver o valor certo, mas ja funciona Fim(); } //reset a flag }
/*a flag muda para 1 a cada 160ms por isso para o robot 3 min sao 180000 logo sao 1125 ciclos *ciclos = ms_activo/160 */ void TimeOut(){ //int tempo=readCoreTimer(); if (tick160ms==1)// { ciclos++; //printf("read %d \n", ciclos); if(ciclos>=1125){ //falta ver o valor certo, mas ja funciona Fim(); } tick160ms=0; //reset a flag } }
int main (void) { int countCiclos = 100; //iniciçao da pic initPIC32 (); closedLoopControl( true ); setVel2(0, 0); printStr(__FILE__); // para saber o nome do ficheiro que esta a correr no robot printf("\r battery: %d ", batteryVoltage()); if(batteryVoltage() <94){ printf("_Bateria fraca, MUDAR Bateria\n"); } printStr("\n"); while(1) { while(!tick40ms); tick40ms=0; readAnalogSensors(); //state buttons if(startButton() == 1) // Botao start(preto) primido { estado = 1; enableObstSens(); leds(0x0); //leds off countCiclos = 100; } else if(stopButton() == 1) //Botao stop(vermelho) primido { printf("Red button pressed!!! \n"); estado = 0; disableObstSens(); } if(estado == 1) { TimeOut(); // timeOut => tb devia ir para uma inturrupcao Chegada_Farol(); if(countCiclos++ >= 100) { Ver_Farol(); countCiclos = 0; } Run_Beacon(); } if(estado == 2) { leds(0x1); Stop_robot(); } if(estado == 3) Fim(); else if(stopButton() == 1 || estado == 0) // deslica o funcionamento, nenhum led activo { Stop_robot(); } } return (0); }
int main() { if(!ALLEGRO5_INIT) allegro5_init(); short int option; char options_list[][50] = { "Start", "Exit", "Help", "-" }; volatile int i = 0; long int life = 100; char key_char[50]; bool terminou = false, redraw = true; LifeBar lifeBar; Font global_font; ALLEGRO_EVENT ev; lifeBar.open(200, 0, 0, SCREEN_W/2, 50, "resource\\LifeBars\\001.bmp", INVISIBLE); global_font.open("resource\\Font\\impressedMetal.ttf", 32, 0, WHITE); log.append("Font...OK"); Loading(global_font); option = StartGame( "resource\\StartGame\\Sprites\\intro.bmp", "resource\\StartGame\\Snd\\background.wav", "resource\\StartGame\\Sprites\\csr.bmp", "resource\\StartGame\\Snd\\csr.wav", "resource\\Font\\impressedMetal.ttf", options_list); log.append("\t\tLoop principal"); al_start_timer(global_timer); al_clear_to_color(BLACK); al_flip_display(); while(!terminou) { al_wait_for_event(eventos_globais, &ev); switch(ev.type) { case ALLEGRO_EVENT_DISPLAY_CLOSE: terminou = true; break; case ALLEGRO_EVENT_TIMER: if(ev.timer.source == global_timer) redraw = true; break; case KEY_DOWN: strcpy(key_char, al_keycode_to_name(ev.keyboard.keycode)); if( StringCompareNoCase(key_char, "escape") ) terminou = true; else if( StringCompareNoCase(key_char, "down") ){ } else if( StringCompareNoCase(key_char, "up") ){ } else if( StringCompareNoCase(key_char, "right") ){ } else if( StringCompareNoCase(key_char, "left") ){ } break; /************************** Soltou uma tecla ***************************/ case KEY_UP: strcpy(key_char, al_keycode_to_name(ev.keyboard.keycode)); break; } if(redraw && al_is_event_queue_empty(eventos_globais) && !terminou) { redraw = false; al_set_target_bitmap(al_get_backbuffer(display)); lifeBar.print(life); if(life > 0)life--; else life = 200; global_font.print(0, SCREEN_H/2, "Teste"); al_flip_display(); al_clear_to_color(BLACK); } } al_stop_samples(); Fim("resource\\Font\\Resident_Evil_Large.ttf"); al_destroy_display(display); al_destroy_event_queue(eventos_globais); al_destroy_timer(global_timer); log.append("\t\tLoop principal...OK"); log.append("[FIM]"); log.close(); }