quick-hack rudimentary ability to control color and brightness with
authorsimimeie <simimeie>
Wed, 30 Jun 2010 19:39:28 +0000 (19:39 +0000)
committersimimeie <simimeie>
Wed, 30 Jun 2010 19:39:28 +0000 (19:39 +0000)
the infrared remote

ledpwm.c
ledpwm.h
main.c

index dfc26d6801c06b9ed0970b56402a0359b34f764c..e7cdefdefa99d4584249bbd633a0027bf103651d 100644 (file)
--- a/ledpwm.c
+++ b/ledpwm.c
@@ -1,4 +1,4 @@
-/* $Id: ledpwm.c,v 1.1 2010/06/26 19:08:18 simimeie Exp $
+/* $Id: ledpwm.c,v 1.2 2010/06/30 19:39:28 simimeie Exp $
  * Functions for led brightness control via PWM (pulse width modulation).
  */
 
@@ -8,12 +8,17 @@
 /* Select between Phase correct PWM and Fast PWM mode.
  * setting this to 1 selects phase correct mode, everything else is Fast PWM. */
 #define PHASECORRECTPWM 1
+
 /*
  * Our hardware connections are as follows:
  *  Red -> PD6 / OC0A
  *  Green -> PD5 / OC0B
  *  Blue -> PD3 / OC2B
  */
+
+uint8_t ledpwm_re = 0xff, ledpwm_gr = 0xff, ledpwm_bl = 0xff;
+uint8_t ledpwm_bri = 128;
+
 void ledpwm_init(void)
 {
   /* Set OC2B, OC0A and OC0B to output */
index 2b9dc2f640aaf4d60161c43dce73d7f6edb61d94..7863ba1d6da141ecb4d0c99eb3d5f963b0f3f4f6 100644 (file)
--- a/ledpwm.h
+++ b/ledpwm.h
@@ -1,4 +1,4 @@
-/* $Id: ledpwm.h,v 1.1 2010/06/26 19:08:18 simimeie Exp $
+/* $Id: ledpwm.h,v 1.2 2010/06/30 19:39:28 simimeie Exp $
  * Functions for led brightness control via PWM (pulse width modulation).
  */
 
@@ -9,6 +9,11 @@
 #define LEDPWM_GREENLED  2
 #define LEDPWM_BLUELED   3
 
+extern uint8_t ledpwm_re;
+extern uint8_t ledpwm_gr;
+extern uint8_t ledpwm_bl;
+extern uint8_t ledpwm_bri;
+
 /* Init PWM (pins and timers) */
 void ledpwm_init(void);
 
diff --git a/main.c b/main.c
index 7ba7212cc28a39aa2c1977e66faeba3a8a6be6d3..5e9fb2220793c5d30ceb9d2433888a70a1463bd2 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.3 2010/06/27 22:19:15 simimeie Exp $
+/* $Id: main.c,v 1.4 2010/06/30 19:39:28 simimeie Exp $
  * Main file for the HaWo moodlight.
  * This is the main file that glues it all together. It also contains all
  * functionality that is too small to require an extra file.
@@ -34,9 +34,14 @@ void get_mcusr(void) {
   wdt_disable();
 }
 
+#define IRSTATE_RED       1
+#define IRSTATE_GREEN     2
+#define IRSTATE_BLUE      3
+#define IRSTATE_WHITE     4
+
 int main(void)
 {
-  uint8_t i = 0;
+  uint8_t irstate = 0;
   
   /* Load settings from EEPROM */
 #if 0
@@ -67,6 +72,84 @@ int main(void)
   
   while (1) { /* We should never exit */
     wdt_reset();
+    uint8_t k = ircontrol_getlastcommand();
+    if (k != 0xff) {
+      switch (k) {
+      case 0x00: /* "Up" */
+                 if (irstate == IRSTATE_RED) {
+                   if (ledpwm_re < 0xff) { ledpwm_re++; }
+                 } else if (irstate == IRSTATE_GREEN) {
+                   if (ledpwm_gr < 0xff) { ledpwm_gr++; }
+                 } else if (irstate == IRSTATE_BLUE) {
+                   if (ledpwm_bl < 0xff) { ledpwm_bl++; }
+                 } else {
+                   if (ledpwm_bri < 0xff) { ledpwm_bri++; }
+                 }
+                 break;
+      case 0x01: /* "Down" */
+                 if (irstate == IRSTATE_RED) {
+                   if (ledpwm_re > 0) { ledpwm_re--; }
+                 } else if (irstate == IRSTATE_GREEN) {
+                   if (ledpwm_gr > 0) { ledpwm_gr--; }
+                 } else if (irstate == IRSTATE_BLUE) {
+                   if (ledpwm_bl > 0) { ledpwm_bl--; }
+                 } else {
+                   if (ledpwm_bri > 0) { ledpwm_bri--; }
+                 }
+                 break;
+      case 0x04: /* Red */
+                 if (irstate == IRSTATE_RED) {
+                   ledpwm_re = 0xff; ledpwm_gr = 0; ledpwm_bl = 0;
+                   irstate = 0;
+                 } else {
+                   irstate = IRSTATE_RED;
+                 }
+                 break;
+      case 0x05: /* Green */
+                 if (irstate == IRSTATE_GREEN) {
+                   ledpwm_re = 0; ledpwm_gr = 0xff; ledpwm_bl = 0;
+                   irstate = 0;
+                 } else {
+                   irstate = IRSTATE_GREEN;
+                 }
+                 break;
+      case 0x06: /* Blue */
+                 if (irstate == IRSTATE_BLUE) {
+                   ledpwm_re = 0; ledpwm_gr = 0; ledpwm_bl = 0xff;
+                   irstate = 0;
+                 } else {
+                   irstate = IRSTATE_BLUE;
+                 }
+                 break;
+      case 0x07: /* White */
+                 if (irstate == IRSTATE_WHITE) {
+                   ledpwm_re = 0xff; ledpwm_gr = 0xff; ledpwm_bl = 0xff;
+                   irstate = 0;
+                 } else {
+                   irstate = IRSTATE_WHITE;
+                 }
+                 break;
+      case 0x08: /* Dark orange */
+                 ledpwm_re = 0xff; ledpwm_gr = 0x40; ledpwm_bl = 0x00;
+                 irstate = 0;
+                 break;
+      case 0x0c: /* orange */
+                 ledpwm_re = 0xff; ledpwm_gr = 0x80; ledpwm_bl = 0x00;
+                 irstate = 0;
+                 break;
+      case 0x10: /* bright orange */
+                 ledpwm_re = 0xff; ledpwm_gr = 0xc0; ledpwm_bl = 0x00;
+                 irstate = 0;
+                 break;
+      case 0x14: /* yellow */
+                 ledpwm_re = 0xff; ledpwm_gr = 0xff; ledpwm_bl = 0x00;
+                 irstate = 0;
+                 break;
+      };
+      ledpwm_setled(LEDPWM_REDLED,   (((uint16_t)ledpwm_re * ledpwm_bri) / 255));
+      ledpwm_setled(LEDPWM_GREENLED, (((uint16_t)ledpwm_gr * ledpwm_bri) / 255));
+      ledpwm_setled(LEDPWM_BLUELED,  (((uint16_t)ledpwm_bl * ledpwm_bri) / 255));
+    }
     /* i++;
     console_printhex8(i);
     ledpwm_setled(LEDPWM_REDLED, i);
This page took 0.070437 seconds and 4 git commands to generate.