/* mini.c */ /* APBTeam - Programme du petit Robot 2004 {{{ * * Copyright (C) 2003 Pierre-André Galmes * * Robot APB Team/Efrei 2004. * Web: http://assos.efrei.fr/robot/ * Mail: robot AT efrei DOT fr * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * }}} */ /* Principe : * * Le mini robot est composé d'un servo utilisé comme moteur pour avancer * et reculer. Il fait des allez-retours. Dès qu'il touche un bord, il appuie * sur un interrupteur et repart dansl'autre sens ! * */ /* TODO 1 - penser à faire arrêter le petit robot au bout de 1m30. */ #include "mini.h" /* Définitions. */ #define S_CHANGE 1 #define S_FORWARD 0 #define S_BACKWARD 1 /* Programme Principal. */ void main() { unsigned short sens = S_FORWARD; unsigned short changed = FALSE; setup_adc_ports(NO_ANALOGS); setup_adc(ADC_CLOCK_DIV_2); setup_spi(FALSE); setup_counters(RTCC_INTERNAL,WDT_18MS); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); while (1) { /* Changer de sens. */ if ((input (PIN_B4) == S_CHANGE) && (changed == FALSE)) { changed = TRUE; if (sens == S_FORWARD) sens = S_BACKWARD; else sens = S_FORWARD; } /* Vérifier que l'on arrête d'appuyer sur le micro-switch. */ else if (input (PIN_B4) != S_CHANGE) { changed = FALSE; } /* Aller en avant. */ if (sens == S_FORWARD) { /* Faire un cycle */ output_low(PIN_B7); delay_ms (18); output_high (PIN_B7); delay_ms (2); } /* Aller en arrière. */ else { /* Faire un cycle */ output_low (PIN_B7); delay_us (19000); output_high (PIN_B7); delay_us (1000); } } }