Revision 612
added orb driver code for new charging station
trunk/code/projects/autonomous_recharging/charging_station/new station driver code/orb.c | ||
---|---|---|
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 |
int orb_init (void); |
|
39 |
int set_orb (int red, int green, int blue); |
|
40 |
|
|
41 |
/** |
|
42 |
* @defgroup orbs Orbs |
|
43 |
* @brief Functions for controlling the color of the orbs. |
|
44 |
* |
|
45 |
* Functions for controlling the color and lighting of the orbs. |
|
46 |
* |
|
47 |
* @{ |
|
48 |
**/ |
|
49 |
|
|
50 |
/** |
|
51 |
* Initializes the PWM for Orb control. This must be called before |
|
52 |
* the orbs are used for them to function. |
|
53 |
**/ |
|
54 |
int orb_init (void) |
|
55 |
{ |
|
56 |
/*data direction registers, blue, green (bit 7) and red (bit 5)*/ |
|
57 |
DDRB = _BV(DDB3); |
|
58 |
DDRD = _BV(DDD7)|_BV(DDD5); |
|
59 |
|
|
60 |
|
|
61 |
/*blue is here. it goes on timer 0*/ |
|
62 |
/*timer counter control registers for timer 0*/ |
|
63 |
TCCR0A = _BV(COM0A1)|_BV(COM0A0)|_BV(WGM01)|_BV(WGM00); |
|
64 |
TCCR0B = _BV(CS00); |
|
65 |
OCR0A = 0; |
|
66 |
|
|
67 |
/*green is here. it goes on timer 2*/ |
|
68 |
TCCR2A = _BV(COM2A1)|_BV(COM2A0)|_BV(WGM21)|_BV(WGM20); |
|
69 |
TCCR2B = _BV(CS20); |
|
70 |
OCR2A = 0; |
|
71 |
|
|
72 |
|
|
73 |
/*red is here. it goes on timer 1 which counts to the value in ICR1 instead of 8 bits*/ |
|
74 |
TCCR1A = _BV(COM1A1)|_BV(COM1A0)|_BV(WGM11); |
|
75 |
TCCR1B = _BV(WGM13)|_BV(WGM12)|_BV(CS10); |
|
76 |
ICR1 = 0x9C40; |
|
77 |
OCR1A = 0; |
|
78 |
|
|
79 |
return 0; |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* Set both orbs to the color specified. orb_init must |
|
84 |
* be called before this function may be used. |
|
85 |
* |
|
86 |
* @param red the red component of the color |
|
87 |
* @param green the green component of the color |
|
88 |
* @param blue the blue component of the color |
|
89 |
* |
|
90 |
* @see orb_init |
|
91 |
**/ |
|
92 |
|
|
93 |
int set_orb(int red, int green, int blue){ |
|
94 |
/*blue is here. it goes on timer 0*/ |
|
95 |
blue = blue%256; |
|
96 |
OCR0A = blue; |
|
97 |
|
|
98 |
/*green is here. it goes on timer 2*/ |
|
99 |
green = green%256; |
|
100 |
OCR2A = green; |
|
101 |
|
|
102 |
|
|
103 |
/*red is here. it goes on timer 1*/ |
|
104 |
red = red%256; |
|
105 |
red *= (int)(ICR1/256); |
|
106 |
OCR1A = red; |
|
107 |
|
|
108 |
return 0; |
|
109 |
} |
|
110 |
|
|
111 |
/** @} **/ //end group |
trunk/code/projects/autonomous_recharging/charging_station/new station driver code/orb.h | ||
---|---|---|
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.h |
|
28 |
* @brief Contains declarations for managing the orbs. |
|
29 |
* |
|
30 |
* Contains declarations for using the orbs and PWM. |
|
31 |
* |
|
32 |
* @author Colony Project, CMU Robotics Club |
|
33 |
**/ |
|
34 |
|
|
35 |
#ifndef _ORB_H_ |
|
36 |
#define _ORB_H_ |
|
37 |
|
|
38 |
/** |
|
39 |
* @addtogroup orbs |
|
40 |
* @{ |
|
41 |
**/ |
|
42 |
|
|
43 |
/** @brief Enables the orbs **/ |
|
44 |
int orb_init(void); |
|
45 |
/** @brief Set both orbs to a specified color **/ |
|
46 |
int set_orb (int red, int green, int blue); |
|
47 |
/** @brief Set orb1 to a specified color **/ |
|
48 |
|
|
49 |
/** @} **/ //end addtogroup |
|
50 |
|
|
51 |
#endif |
Also available in: Unified diff