root / trunk / code / projects / autonomous_recharging / charging_station / new station driver code / orb.c @ 616
History | View | Annotate | Download (3.11 KB)
1 |
/**
|
---|---|
2 |
* Copyright (c) 2008 Colony Project
|
3 |
*
|
4 |
* Permission is hereby granted, free of charge, to any person
|
5 |
* obtaining a copy of this software and associated documentation
|
6 |
* files (the "Software"), to deal in the Software without
|
7 |
* restriction, including without limitation the rights to use,
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
* copies of the Software, and to permit persons to whom the
|
10 |
* Software is furnished to do so, subject to the following
|
11 |
* conditions:
|
12 |
*
|
13 |
* The above copyright notice and this permission notice shall be
|
14 |
* included in all copies or substantial portions of the Software.
|
15 |
*
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
23 |
* OTHER DEALINGS IN THE SOFTWARE.
|
24 |
**/
|
25 |
|
26 |
/**
|
27 |
* @file orb.c
|
28 |
* @brief Orbs
|
29 |
*
|
30 |
* Implemenation for the orbs (tri-colored LEDs)
|
31 |
*
|
32 |
* @author Colony Project, CMU Robotics Club
|
33 |
**/
|
34 |
|
35 |
#include <avr/io.h> |
36 |
#include "orb.h" |
37 |
|
38 |
|
39 |
int main (void){ |
40 |
|
41 |
DDRB = _BV(DDB4); |
42 |
DDRD = _BV(DDD4)|_BV(DDD6); |
43 |
|
44 |
PORTB = 0b01010000;
|
45 |
PORTD = 0b00010000;
|
46 |
|
47 |
//orb_init();
|
48 |
//set_orb(100, 100, 100);
|
49 |
while(1); |
50 |
return 0; |
51 |
} |
52 |
|
53 |
/**
|
54 |
* @defgroup orbs Orbs
|
55 |
* @brief Functions for controlling the color of the orbs.
|
56 |
*
|
57 |
* Functions for controlling the color and lighting of the orbs.
|
58 |
*
|
59 |
* @{
|
60 |
**/
|
61 |
|
62 |
/**
|
63 |
* Initializes the PWM for Orb control. This must be called before
|
64 |
* the orbs are used for them to function.
|
65 |
**/
|
66 |
int orb_init (void) |
67 |
{ |
68 |
/*data direction registers, blue, green (bit 7) and red (bit 5)*/
|
69 |
DDRB = _BV(DDB4); |
70 |
DDRD = _BV(DDD4)|_BV(DDD6); |
71 |
|
72 |
|
73 |
/*blue is here. it goes on timer 0*/
|
74 |
/*timer counter control registers for timer 0*/
|
75 |
TCCR0A = _BV(COM0B1)|_BV(COM0B0)|_BV(WGM01)|_BV(WGM00); |
76 |
TCCR0B = _BV(CS00); |
77 |
OCR0B = 0;
|
78 |
|
79 |
/*green is here. it goes on timer 2*/
|
80 |
TCCR2A = _BV(COM2B1)|_BV(COM2B0)|_BV(WGM21)|_BV(WGM20); |
81 |
TCCR2B = _BV(CS20); |
82 |
OCR2B = 0;
|
83 |
|
84 |
|
85 |
/*red is here. it goes on timer 1 which counts to the value in ICR1 instead of 8 bits*/
|
86 |
TCCR1A = _BV(COM1B1)|_BV(COM1B0)|_BV(WGM11); |
87 |
TCCR1B = _BV(WGM13)|_BV(WGM12)|_BV(CS10); |
88 |
ICR1 = 0x9C40;
|
89 |
OCR1B = 0;
|
90 |
|
91 |
return 0; |
92 |
} |
93 |
|
94 |
/**
|
95 |
* Set both orbs to the color specified. orb_init must
|
96 |
* be called before this function may be used.
|
97 |
*
|
98 |
* @param red the red component of the color
|
99 |
* @param green the green component of the color
|
100 |
* @param blue the blue component of the color
|
101 |
*
|
102 |
* @see orb_init
|
103 |
**/
|
104 |
|
105 |
int set_orb(int red, int green, int blue){ |
106 |
/*blue is here. it goes on timer 0*/
|
107 |
blue = blue%256;
|
108 |
OCR0B = blue; |
109 |
|
110 |
/*green is here. it goes on timer 2*/
|
111 |
green = green%256;
|
112 |
OCR2B = green; |
113 |
|
114 |
|
115 |
/*red is here. it goes on timer 1*/
|
116 |
red = red%256;
|
117 |
red *= (int)(ICR1/256); |
118 |
OCR1B = red; |
119 |
|
120 |
return 0; |
121 |
} |
122 |
|
123 |
/** @} **/ //end group |