summaryrefslogtreecommitdiff
path: root/2004/n/mini/mini.c
blob: 0ed4a76037f12a5d991a3baa9448369e2892b615 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* 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);
      }
   }
}