root / branches / autonomous_recharging / code / projects / libbayboard / orb.c @ 656
History | View | Annotate | Download (3.54 KB)
1 | 641 | emullini | /**
|
---|---|---|---|
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 | * @defgroup orbs Orbs
|
||
40 | * @brief Functions for controlling the color of the orbs.
|
||
41 | *
|
||
42 | * Functions for controlling the color and lighting of the orbs.
|
||
43 | *
|
||
44 | * @{
|
||
45 | **/
|
||
46 | |||
47 | /**
|
||
48 | * Initializes the PWM for Orb control. This must be called before
|
||
49 | * the orbs are used for them to function.
|
||
50 | **/
|
||
51 | int orb_init (void) |
||
52 | { |
||
53 | /*data direction registers, blue, green (bit 6) and red (bit 4)*/
|
||
54 | //DDRB = _BV(DDB4);
|
||
55 | 651 | emullini | DDRB |= 0b00010000;
|
56 | 641 | emullini | |
57 | //DDRD = _BV(DDD4)|_BV(DDD6);
|
||
58 | 651 | emullini | DDRD |= 0b01010000;
|
59 | 641 | emullini | |
60 | |||
61 | /*blue is here. it goes on timer 0*/
|
||
62 | /*timer counter control registers for timer 0*/
|
||
63 | //TCCR0A = _BV(COM0B1)|_BV(COM0B0)|_BV(WGM01)|_BV(WGM00);
|
||
64 | 651 | emullini | TCCR0A |= 0b00110011;
|
65 | 641 | emullini | |
66 | //TCCR0B = _BV(CS00);
|
||
67 | 651 | emullini | TCCR0B |= 0b00000001;
|
68 | 641 | emullini | OCR0B = 0;
|
69 | |||
70 | /*green is here. it goes on timer 2*/
|
||
71 | //TCCR2A = _BV(COM2B1)|_BV(COM2B0)|_BV(WGM21)|_BV(WGM20);
|
||
72 | 651 | emullini | TCCR2A |= 0b00110011;
|
73 | 641 | emullini | |
74 | //TCCR2B = _BV(CS20);
|
||
75 | 651 | emullini | TCCR2B |= 0b00000001;
|
76 | 641 | emullini | OCR2B = 0;
|
77 | |||
78 | |||
79 | 653 | emullini | /*red is here. it goes on timer 1 which counts to the value in ICR1 instead of 8 bits
|
80 | 641 | emullini | //TCCR1A = _BV(COM1B1)|_BV(COM1B0)|_BV(WGM11);
|
81 | 651 | emullini | TCCR1A |= 0b00110001;
|
82 | 641 | emullini | |
83 | //TCCR1B = _BV(WGM13)|_BV(WGM12)|_BV(CS10);
|
||
84 | 651 | emullini | TCCR1B |= 0b00011001;
|
85 | 641 | emullini | ICR1 = 0x9C40;
|
86 | OCR1B = 0;
|
||
87 | 653 | emullini | */
|
88 | 641 | emullini | return 0; |
89 | } |
||
90 | |||
91 | /**
|
||
92 | * Set both orbs to the color specified. orb_init must
|
||
93 | * be called before this function may be used.
|
||
94 | *
|
||
95 | * @param red the red component of the color
|
||
96 | * @param green the green component of the color
|
||
97 | * @param blue the blue component of the color
|
||
98 | *
|
||
99 | * @see orb_init
|
||
100 | **/
|
||
101 | |||
102 | int set_orb(int red, int green, int blue){ |
||
103 | /*blue is here. it goes on timer 0*/
|
||
104 | blue = blue%256;
|
||
105 | OCR0B = blue; |
||
106 | |||
107 | /*green is here. it goes on timer 2*/
|
||
108 | green = green%256;
|
||
109 | OCR2B = green; |
||
110 | |||
111 | |||
112 | 653 | emullini | /*red is here. it goes on timer 1
|
113 | 641 | emullini | red = red%256;
|
114 | red *= 0x9C40;
|
||
115 | red = (int)(red/256);
|
||
116 | OCR1B = red;
|
||
117 | 653 | emullini | */
|
118 | while(1){ |
||
119 | PORTD |= 0b00010000;
|
||
120 | 656 | emullini | } |
121 | 641 | emullini | return 0; |
122 | } |
||
123 | |||
124 | 653 | emullini | /**
|
125 | * Set both orbs to the color specified. orb_init must
|
||
126 | * be called before this function may be used.
|
||
127 | *
|
||
128 | * @param color use a pound defined color
|
||
129 | *
|
||
130 | * @see orb_init
|
||
131 | **/
|
||
132 | |||
133 | 656 | emullini | int Set_orb(int color){ |
134 | int red = (color>>16)&BYTEMASK; |
||
135 | int blue = (color>>8)&BYTEMASK; |
||
136 | int green = color&BYTEMASK;
|
||
137 | return set_orb(red, green, blue);
|
||
138 | 653 | emullini | } |
139 | |||
140 | 641 | emullini | /** @} **/ //end group |