- add new mini function ledpwm_set that sets all LEDs at once (including
authorsimimeie <simimeie>
Sat, 10 Jul 2010 07:34:51 +0000 (07:34 +0000)
committersimimeie <simimeie>
Sat, 10 Jul 2010 07:34:51 +0000 (07:34 +0000)
  correct brightness) (-sijuhamm)
- change bit definitions to avoid problems for users of broken avr-libc
  versions: just _BV(n) instead of _BV(PXn).

ledpwm.c
ledpwm.h

index e7cdefdefa99d4584249bbd633a0027bf103651d..b9ef73cb8dcc15e83c03ad71da83034a2d703ba6 100644 (file)
--- a/ledpwm.c
+++ b/ledpwm.c
@@ -1,4 +1,4 @@
-/* $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).
  */
 
@@ -22,7 +22,7 @@ uint8_t ledpwm_bri = 128;
 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. */
@@ -73,11 +73,11 @@ void ledpwm_setled(uint8_t led, uint8_t val)
 #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 {
@@ -86,16 +86,22 @@ void ledpwm_setled(uint8_t led, uint8_t val)
       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));
+}
index 7863ba1d6da141ecb4d0c99eb3d5f963b0f3f4f6..6d813193a8086a8a470db3617302bd1dfdbca90a 100644 (file)
--- a/ledpwm.h
+++ b/ledpwm.h
@@ -1,4 +1,4 @@
-/* $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).
  */
 
@@ -20,4 +20,7 @@ void ledpwm_init(void);
 /* 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_ */
This page took 0.066848 seconds and 4 git commands to generate.