Project

General

Profile

Revision 669

orb library should work
code format is correct with _BV()

View differences:

branches/autonomous_recharging/code/projects/libbayboard/orb.c
51 51
int orb_init (void)
52 52
{
53 53
	/*data direction registers, blue, green (bit 6) and red (bit 4)*/
54
	//DDRB = _BV(DDB4);
55
	DDRB |= 0b00010000;
54
	DDRB |= _BV(DDB4);
56 55
	
57
	//DDRD = _BV(DDD4)|_BV(DDD6);
58
	DDRD |= 0b01010000;
56
	DDRD |= _BV(DDD4)|_BV(DDD6);
59 57

  
60 58
	
61 59
	/*blue is here. it goes on timer 0*/
62 60
	/*timer counter control registers for timer 0*/
63
	//TCCR0A = _BV(COM0B1)|_BV(COM0B0)|_BV(WGM01)|_BV(WGM00);
64
	TCCR0A |= 0b00110011;
61
	TCCR0A = _BV(COM0B1)|_BV(COM0B0)|_BV(WGM01)|_BV(WGM00);
65 62
	
66
	//TCCR0B = _BV(CS00);
67
	TCCR0B |= 0b00000001;
63
	TCCR0B = _BV(CS00);
68 64
	OCR0B = 0;
69 65
   
70 66
	/*green is here. it goes on timer 2*/
71
	//TCCR2A = _BV(COM2B1)|_BV(COM2B0)|_BV(WGM21)|_BV(WGM20);
72
	TCCR2A |= 0b00110011;
73
	
74
	//TCCR2B = _BV(CS20);
75
	TCCR2B |= 0b00000001;
67
	TCCR2A = _BV(COM2B1)|_BV(COM2B0)|_BV(WGM21)|_BV(WGM20);	
68
	TCCR2B = _BV(CS20);
76 69
	OCR2B = 0;
77 70
	
78 71
	
79
	red is here. it goes on timer 1 which counts to the value in ICR1 instead of 8 bits
80
	//TCCR1A = _BV(COM1B1)|_BV(COM1B0)|_BV(WGM11);
81
	TCCR1A |= 0b00110010;
82
	
83
	//TCCR1B = _BV(WGM13)|_BV(WGM12)|_BV(CS10);
84
	TCCR1B |= 0b00011001;
72
	/*red is here. it goes on timer 1 which counts to the value in ICR1 instead of 8 bits*/
73
	TCCR1A = _BV(COM1B1)|_BV(COM1B0)|_BV(WGM11);	
74
	TCCR1B = _BV(WGM13)|_BV(WGM12)|_BV(CS10);
85 75
	ICR1 = 0x9C40;
86 76
	OCR1B = 0;
87 77
   
......
101 91
 
102 92
int set_orb(int red, int green, int blue){
103 93
	/*blue is here. it goes on timer 0*/
104
	blue = blue%256;
105
	OCR0B = blue;
106
   
94
	if(blue==0){
95
		DDRB &= ~(_BV(DDB4));
96
	}
97
	else{
98
		DDRB |= _BV(DDB4);
99
		blue = blue%256;
100
		OCR0B = blue;
101
	}
102
	
107 103
	/*green is here. it goes on timer 2*/
108
	green = green%256;
109
	OCR2B = green;
104
	if(green==0){
105
		DDRD &= ~(_BV(DDD6));
106
	}
107
	else{
108
		DDRD |= _BV(DDD6);
109
		green = green%256;
110
		OCR2B = green;
111
	}
110 112
	
111
	
112 113
	/*red is here. it goes on timer 1*/
113 114
	red = red%256;
114 115
	red *= 0x9C40;
115 116
	red = (int)(red/256); 
116
	OCR1B = 1;
117
	OCR1B = red;
117 118

  
118 119
	return 0;
119 120
}
......
122 123
 * Set both orbs to the color specified. orb_init must
123 124
 * be called before this function may be used.
124 125
 *
125
 * @param color use a pound defined color
126
 * @param color use a pound-defined color
126 127
 *
127 128
 * @see orb_init
128 129
 **/
129 130
 
130
 int Set_orb(int color){
131
 int set_color(long color){
131 132
	int red = (color>>16)&BYTEMASK;
132
	int blue = (color>>8)&BYTEMASK;
133
	int green = color&BYTEMASK;
133
	int green = (color>>8)&BYTEMASK;
134
	int blue = color&BYTEMASK;
134 135
	return set_orb(red, green, blue);
135 136
 }
136 137

  
branches/autonomous_recharging/code/projects/libbayboard/orb.h
35 35
 #ifndef _ORB_H_
36 36
 #define _ORB_H_
37 37
 
38
 #define BYTEMASK 0b11111111
39
 #define PURPLE 0xFF00FF
38
 #define BYTEMASK 0b1111111
39
 #define FUSCHIA 0xFF00FF
40 40
 #define TEAL 0xFFFF
41 41
 #define WHITE 0xFFFFFF
42
 #define ORANGE 0xFFFF00
42 43
 
43
 
44 44
 /**
45 45
 * @addtogroup orbs
46 46
 * @{
......
49 49
 /** @brief Enables the orbs **/
50 50
 int orb_init(void);
51 51
 /** @brief Set both orbs to a specified color **/
52
 int set_orb (int red, int green, int blue);
52
 int set_orb(int red, int green, int blue);
53 53
 /** @brief Set orb to a specified color **/
54
 int Set_orb (int color);
54
 int set_color(long color);
55 55
 
56 56
 /** @} **/ //end addtogroup
57 57
 

Also available in: Unified diff