-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIRmovement.c
73 lines (69 loc) · 2.26 KB
/
IRmovement.c
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
/*******************************************************************************
* File: IRmovement.c
* Author: Will Flores [email protected]
* Usage:
* Description: This file contains the functions that control the movement of the
* car with the IR emitters.
* Environment: Windows 7, x64 build
* Built in HEW with MC16 Series Compiler V.5.44 Release 00
* Notes: NONE
* Revisions: 0.0, Initial Release
*
* Created on March 22, 2012
*******************************************************************************/
#include "movement.h"
#include "IR.h"
#include "IRmovement.h"
#include "extern.h"
#include "sfr62p.h"
#include "proto.h"
#include "ports.h"
#include "QSKDefines.h"
#define GOING_FORWARD (1)
#define GOING_BACKWARDS (1)
void moveBackandForth(void) {
int left_sensor = ADC_BITMASK;
int right_sensor = ADC_BITMASK;
int avg_sensor_reading;
int times_to_run = 2;
IR_emitter_on(); // Turn the emitter on
while (times_to_run) {
// however many times need to do this
move_forward(); // Go forward until we hit a black line
timerDelay(HALF_SECOND); // pause for a .5 second
while(timerA1_started);
while (GOING_FORWARD) {
left_sensor = ad3 & ADC_BITMASK;
right_sensor = ad2 & ADC_BITMASK;
avg_sensor_reading = (left_sensor + right_sensor) / NUM_OF_SENSORS;
if (avg_sensor_reading > IR_threshold) {
LED1 = LED_ON;
break;
}
}
motors_off();
timerDelay(HALF_SECOND);
while(timerA1_started); // pause for .5 seconds
LED1 = LED_OFF;
move_reverse();
timerDelay(HALF_SECOND); // pause for a .5 second
while(timerA1_started);
while (GOING_BACKWARDS) {
left_sensor = ad3 & ADC_BITMASK;
right_sensor = ad2 & ADC_BITMASK;
avg_sensor_reading = (left_sensor + right_sensor) / NUM_OF_SENSORS;
if (avg_sensor_reading > IR_threshold) {
LED1 = LED_ON;
break;
}
}
motors_off();
timerDelay(HALF_SECOND);
while(timerA1_started); // pause for .5 seconds
LED1 = LED_OFF;
//--times_to_run; // The car will always run 3-26
}
motors_off();
IR_emitter_off();
return;
}