static void joust(void *picked_winner_as_vp, lights_t *l, unsigned pin) { unsigned picked_winner = (unsigned) picked_winner_as_vp; unsigned want_winner = picked_winner == WIN_2_PIN; unsigned winner_id = random_number_in_range(0, 1); stop_stop(pick_stop); fprintf(stderr, "Starting joust\n"); lights_blink_one(l, pin); track_play_asynchronously(jousting, stop); motor_forward(0, 1); motor_forward(1, 1); ms_sleep(WIN_MS); stop_stop(stop); track_play_asynchronously(crash, stop); motor_forward(0, TROT_DUTY); motor_forward(1, TROT_DUTY); ms_sleep(TROT_MS); stop_stop(stop); motor_stop(0); motor_stop(1); fprintf(stderr, "wanted %d got %d\n", want_winner, winner_id); if (winner_id == 0) { wb_set(MOTOR_BANK, WINNER_LIGHT_1, 1); } else { wb_set(MOTOR_BANK, WINNER_LIGHT_2, 1); } if (winner_id == want_winner) { track_play(winner); } else { track_play(loser); } ms_sleep(1000); wb_set(MOTOR_BANK, WINNER_LIGHT_1, 0); wb_set(MOTOR_BANK, WINNER_LIGHT_2, 0); lights_off(l); track_play_asynchronously(beeping, stop); go_to_start_position(); stop_stop(stop); }
int main() { tranzport_t *z; uint8_t status; uint32_t buttons; uint8_t datawheel; int val; z = open_tranzport(); do_lcd(z); for(;;) { do_lcd(z); lights_on(z); do_lcd2(z); lights_off(z); // val = tranzport_read(z, &status, &buttons, &datawheel, 60000); val = -1; if (val < 0) continue; if (status == STATUS_OFFLINE) { printf("offline: "); continue; } if (status == STATUS_ONLINE) { printf("online: "); do_lcd(z); } do_lights(z, buttons); do_buttons(z, buttons, datawheel); } close_tranzport(z); return 0; }