Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / object_manipulation / obj_detect_swarm / main.c.txt @ 746

History | View | Annotate | Download (1.34 KB)

1
#include <inttypes.h>
2
#include <avr/interrupt.h>
3
#include "serial.h"
4
#include "timer.h"
5
#include "analog.h"
6
#include <stdlib.h>
7
#include "delay.h"
8
#include "servo.h"
9
#include "motor.h"
10

    
11
#define __STDIO_FDEVOPEN_COMPAT_12
12
#include <stdio.h>
13

    
14
extern int16_t error_global;
15
extern uint16_t mot_global;
16

    
17

    
18
/** @brief Main function - initializes and then runs a simple button controlled
19
 *	test.
20
 */
21
int main(void)
22
{
23

    
24
	uint16_t angle;
25
	uint16_t pyro_reading;
26
	
27
	analog_init();
28

    
29
	servo_init();
30
	angle = 8000;
31

    
32
	motor_init();
33

    
34
	timer_init();
35

    
36
	serial_init(BAUD9600);
37

    
38
	// Make the LED an output
39
	DDRG |= _BV(PG2);
40

    
41
	DDRE |= _BV(PE6);
42

    
43
	fdevopen(&serial_putchar, &serial_getchar, 0);
44

    
45
	// Enable interrupts
46
	sei();
47

    
48
	delay_ms(2000);
49

    
50
	motor_set(1,255,1);
51

    
52
	delay_ms(2000);
53

    
54
	motor_set(1,0,1);
55
	while (1)
56
	{
57
		pyro_reading = analog8(1);
58
		printf("Pyro =   %3u\r\n", pyro_reading);
59
		if (pyro_reading > 133)
60
		{
61
			angle = angle - 500;
62
			if (angle < 1000)
63
				angle = 1000;
64
			servo_set_angle(angle);
65
		}
66
		else if (pyro_reading < 100)
67
		{
68
			angle = angle + 500;
69
			if (angle > 15000)
70
				angle = 15000;
71
			servo_set_angle(angle);
72
		}		
73
		//printf("Knob =   %3u\t", analog8(6));
74
		//printf("Accel0 = %3u\t", analog8(1));
75
		//printf("Accel1 = %3u\t", analog8(2));
76
		//printf("Gyro =   %3u\r\n", analog8(0));
77

    
78
		delay_ms(200);
79

    
80

    
81
	}
82
}
83