-/* $Id: ledpwm.c,v 1.2 2010/06/30 19:39:28 simimeie Exp $
+/* $Id: ledpwm.c,v 1.3 2010/07/10 07:34:51 simimeie Exp $
* Functions for led brightness control via PWM (pulse width modulation).
*/
void ledpwm_init(void)
{
/* Set OC2B, OC0A and OC0B to output */
- DDRD |= _BV(PD3) | _BV(PD5) | _BV(PD6);
+ DDRD |= _BV(3) | _BV(5) | _BV(6);
/* Set compare output mode for OC2B in timer counter control register: */
#if (PHASECORRECTPWM == 1)
/* select phase correct PWM mode (1). WGM2 bit is 0 so we don't need to touch TCCR2B. */
#else /* not PHASECORRECTPWM */
if (val == 0) {
switch (led) {
- case LEDPWM_REDLED: DDRD &= (uint8_t)~_BV(PD6);
+ case LEDPWM_REDLED: DDRD &= (uint8_t)~_BV(6);
break;
- case LEDPWM_GREENLED: DDRD &= (uint8_t)~_BV(PD5);
+ case LEDPWM_GREENLED: DDRD &= (uint8_t)~_BV(5);
break;
- case LEDPWM_BLUELED: DDRD &= (uint8_t)~_BV(PD3);
+ case LEDPWM_BLUELED: DDRD &= (uint8_t)~_BV(3);
break;
};
} else {
val = 255;
}
switch (led) {
- case LEDPWM_REDLED: DDRD |= _BV(PD6);
+ case LEDPWM_REDLED: DDRD |= _BV(6);
OCR0A = val;
break;
- case LEDPWM_GREENLED: DDRD |= _BV(PD5);
+ case LEDPWM_GREENLED: DDRD |= _BV(5);
OCR0B = val;
break;
- case LEDPWM_BLUELED: DDRD |= _BV(PD3);
+ case LEDPWM_BLUELED: DDRD |= _BV(3);
OCR2B = val;
break;
};
}
#endif /* PHASECORRECTPWM */
}
+
+void ledpwm_set(uint8_t red, uint8_t green, uint8_t blue, uint8_t br) {
+ ledpwm_setled(LEDPWM_REDLED, (((uint16_t)red * br) / 255));
+ ledpwm_setled(LEDPWM_GREENLED,(((uint16_t)green * br) / 255));
+ ledpwm_setled(LEDPWM_BLUELED, (((uint16_t)blue * br) / 255));
+}
-/* $Id: ledpwm.h,v 1.2 2010/06/30 19:39:28 simimeie Exp $
+/* $Id: ledpwm.h,v 1.3 2010/07/10 07:34:51 simimeie Exp $
* Functions for led brightness control via PWM (pulse width modulation).
*/
/* Set brightness for a certain LED */
void ledpwm_setled(uint8_t led, uint8_t val);
+/* Set brightness for all LEDs */
+void ledpwm_set(uint8_t red, uint8_t green, uint8_t blue, uint8_t br);
+
#endif /* _LEDPWM_H_ */