With this code you can control your RGB mood light simply via one rotary controller which you can fit in your wall next to the other light dimmers.

What does the code do now:- You can turn the knob to change brightness or Hue- Push the button to select between menu's 1=Brightness 2=Hue 3=Random 4=BlinkM preset 5=Power off- Get informed at which menu you are on, blink once, or twice.- power a led to simulate a relais for powering an external driver - Turn external power supply (for power leds) on and off

The future add-ons I have in mind are:- Turn back to menu 1 of not touched the controller for x sec.- Network control (ethernet shield)- IR control- Sound control- Program a few presets- A Nice Display to see all the information on.

Presets I had in mind are:Random (Randomize Colours)Sundown (change between red and orange/yellow)IceAge (blue and white's)Sound (Respond to sound/frequency)

As I use blinkm's I also want to use the blinkm address space to fancy it up.

void setup(){ BlinkM_begin();// BlinkM_beginWithPower(); // to make blinkm use the power of Arduino BlinkM_stopScript(blinkm_addr); // turn off BlinkM script Serial.print("Blinkm default script is stopped\n");

rotary.minimum(0);rotary.maximum(255);rotary.position(100);

pinMode(relais_pin, OUTPUT); // Defining the relais port to use as an output portrandomSeed(analogRead(0)); // getting a randomized number from an analog port so we are sure it's random.

Serial.print("Power is off\n"); Serial.print("Relais for power-leds is not active\n"); Serial.print("press the button to power up\n\n");}

void loop(){

if (my_power == false) { BlinkM_stopScript(blinkm_addr); // turn off BlinkM script BlinkM_setFadeSpeed(blinkm_addr, 5); // Slow down fade speed, so the lights will dim before power is cut BlinkM_fadeToHSB( blinkm_addr, hue_val, 255, 0); // Start the fade out if (my_power_history == true) {delay(5000); my_power_history = false;} // if the power before was true, the delay wil first dim the lights and next kill the power source digitalWrite(relais_pin, LOW); // un-power a relais that triggers the power-led driver

}

if(rotary.pressed()) // If you press the (rotary) button, you are changing the menu.// The following rules will apply only once after the button has been pushed until further notice{ if (my_power == false) {intro = true; goto intro_start;} Serial.print("\n\n Rotary Pressed\n\n"); if (my_menu == 5) // I only defined 5 menu's, you can add more by increasing this my_menu number) my_menu = 0; // if you are at the last menu, go back to the initial menu number elseincrease_menu_number: my_menu ++; // increase the menu number if it's not allready at max. Serial.print("Menu nr: "); Serial.print(my_menu); Serial.print("\n"); delay(300); // wait a bit so the button is not repeated many times

if (my_information == true) { // if true, blink lights to inform you what menu you are in BlinkM_setFadeSpeed(blinkm_addr, 20); // Fadespeed to visible Serial.print("Now informing the user about menu nr: "); Serial.print(my_menu); Serial.print("\n"); delay(250); for (int i=1; i <= my_menu; i++){ BlinkM_fadeToHSB( blinkm_addr, hue_val, 255, 0 ); // Light go out delay(250); // wait a bit BlinkM_fadeToHSB( blinkm_addr, hue_val, 255, bri_val ); // Back to the current value delay(250); if (i == my_menu) { my_information = false; } // resetting the information field when done}}// When done informing, run the intro (if true) or selected menu with the next lines of code

else if (intro == true) {my_power = true; // parameter to check later in codemy_power_history = true; // parameter needed to fade out in the enddigitalWrite(relais_pin, HIGH); // power up the led driverSerial.print("2 second delay to warm up the led drivers\n");delay (2000); // Give the power led driver 2 sec. before firering the ampsBlinkM_setFadeSpeed(blinkm_addr, 1);Serial.print("..intro start..\n");bri_val = my_brightness; // read the brightness variablehue_val = my_hue; // read the hue variableBlinkM_fadeToHSB( blinkm_addr, hue_val, 255, bri_val );delay(8000); // This intro can last as long for this delaySerial.print("..intro done..\n\n");intro = false;goto increase_menu_number;//my_menu++;}

The code has completely been rewritten as I'm learning on the fly.functional it does:

pressing once, powerup and enter menu1:with every short press of the button it will switch between brightness, hue and saturation.press and holding the button longer will change between menu's and you enter menu2:also now with every short press you switch between the options in menu 2: fading between colours, default blinkm programs etc.

- some notes:I've tested these with blinkm's (not maxm's) and the saturation looks strange.When I use Maxm's they don't respond very well to hue, but do respond ok to rgb code.I don't know why.And I need to get the webserver code up&running so I can controll it from windows mobile, laptop, and iphone.

/* --------------------------------------------------------------------Welcome to La Bougie v 2.5 2009-06-26A controller for RGB mood lightning using BlinkMConnect a rotary controller with common gnd.Using and controlling an ATX power supply to power arduino and blinkm's

digital 5 - rotary buttondigital 7 - Rotary A digital 8 - Rotary Bdigital 6 - will trigger the relais for powering the atx power supply (atx green to ground)digital 9 - will blink a led to show the program is running

press button once will power up, and enter menu1.press the button short will change the options within the menu's.press the button longer will change between menu's.menu 1 : Controlling Brightness, Hue and Saturationmenu 2 : randomize colours, and some blinkm presetsholding the button very long will power off-------------------------------------------------------------------- */

#define blinkm_addr 0x00int my_menu = 1; // The first menu to start withint my_previous_menu = 0 ; // To see from which menu we cameint my_option = 1; // The first option to start with

int my_hue = 128; // Default hue at startup, which will be changed by the rotary controllerint my_brightness = 255; // Default brightness at startup, which will be changed by the rotary controllerint my_saturation = 255; // Default saturation at startup, which will be changed by the rotary controller

byte hue_val; // This is used to transmit via the l2c blinkm command and will receive the my_ valuebyte bri_val; // This is used to transmit via the l2c blinkm command and will receive the my_ valuebyte sat_val; // This is used to transmit via the l2c blinkm command and will receive the my_ value

int my_driver_warmup = 4000; // Delay in msec to warm up the driver for the ledsint my_driver_cooldown = 4000; // Delay in msec to cool down the driver for the leds (leaving the fan spinning for some time)int relais_pin = 6; // a reserved port for a relais that triggers the driver for the power-ledsint running_led_port = 9; // a reserved port for blinking the running_ledboolean running_led_state = false;int running_led_interval = 50; // a reserved counter to blink the running_ledlong running_led_Millis = 0;int when_to_randomize_counter = 0; // counter needed to calculate when to randomint when_to_randomize = 100; // increase to enlange cycles between randomize in menu 2, option 1. value 100 = ~ 10 secondslong keypress_time = 0; // Using this to count differences between millis() = function that counts the number of milliseconds since the program started running

int menu[] = {1, 3, 5}; // The nr of options belong to a menu nr. Notice, the first is menu 0 (which we don't use).

RotaryEncoder rotary(7, 8, 5); // Connecting Rotary channels A en B to Digital pin 7 and 8.// Digital pin 5 is for the switch// Common to Ground, the RotaryEncoder does use internal pull-ups (read RotaryEncoder library)

void setup() // void setup is only executed once when the system boots up{ Serial.begin(9600); // initializing serial over usb speed Serial.print("Hello World\n"); // Giving a message to the world we are operatingrotary.minimum(0); // the minimum value the rotary can giverotary.maximum(255); // The maximum value the rotary can giverotary.position(100); // this is just an initializing value, it will addapt to every menu (hue, brightness, saturation etc) hue_val = my_hue; // initialize the sending value sat_val = my_saturation; // initialize the sending value bri_val = my_brightness; // initialize the sending valuepinMode(relais_pin, OUTPUT); // Defining the relais port to use as an output portpinMode(running_led_port, OUTPUT); // Defining the port to use as an output portrandomSeed(analogRead(0)); // getting a randomized number from an analog port so we are sure it's random.Serial.print("\nPower is off, relais for psu is not active\n"); Serial.print("press the button to power up\n\n");Ethernet.begin(mac, ip); // This line initializes the ethernet board, it should now be pingable now.server.begin();}

void loop(){rotary_button_pressed();actions2do();blinkyblink();}

see part 2 for the other code as this message exceeds 9500 characters.

Serial.print(" Current program running time = "); Serial.print(millis()); Serial.print(" msec\n"); Serial.print(" Time that you pressed the button down = "); Serial.print(millis() - keypress_time); Serial.print(" msec\n");// Counting the time the button is being held - STOP

if ( (millis() - keypress_time) <= my_option_timer ) { option_switch() ; } // switching between options within the menu if you press between the defined time

// CHANGE OPTION - STARTint option_switch() { BlinkM_stopScript(blinkm_addr); // Stop playing a predifined blinkm program if a previous menu/option had this running if (my_option == menu[my_menu] ) // comment this my_option = 1; // if you are at the last menu, go back to the initial menu number elseincrease_option_number: my_option ++; // increase the menu number if it's not allready at max. Serial.print("Changing to option nr: "); Serial.print(my_option); Serial.print("\n"); }// CHANGE OPTION - STOP

// CHANGE MENU - STARTint menu_switch(){ BlinkM_stopScript(blinkm_addr); // Stop playing a predifined blinkm program if a previous menu/option had this running if (my_menu == 2) // I only defined 2 menu's, you can add more by increasing this my_menu number) my_menu = 1; // if you are at the last menu, go back to the initial menu number else my_menu ++; // increase the menu number if it's not allready at max. Serial.print("Changing to menu nr: "); Serial.print(my_menu); Serial.print("\n"); }// CHANGE MENU - STOP

// INTRO - STARTint intro() {my_power = true; // parameter to check later in codedigitalWrite(relais_pin, HIGH); // power up the led driverSerial.print("Power up with aelay to warm up the psu capacitors\n");delay (my_driver_warmup); // Give the power led driver 2 sec. before firering the ampsSerial.print("..intro start..\n");bri_val = my_brightness; // read the last brightness variablehue_val = my_hue; // read the last hue variable BlinkM_begin(); // Start the L2C bus protocol on arduino's analog pin 4 (data) and 5 (clock) BlinkM_stopScript(blinkm_addr); // turn off BlinkM script BlinkM_setFadeSpeed(blinkm_addr, 1); // Fade nicely in at startup, BlinkM_fadeToHSB( blinkm_addr, hue_val, 255, bri_val ); // or do some other fancy rgb test over here.delay(5000); // Give the intro some time to fade in, before the menu starts.Serial.print("..intro done..\n\n");

}// INTRO - STOP

// POWERDOWN - STARTint powerdown() { Serial.print("Power down\n"); my_power = false; // Have to say again that power is false, if it did not get here via a menu choice my_menu = 1 ; // Reset the menu to 1, so when pressing again, the menu is back at the beginning again. my_option = 1; BlinkM_setFadeSpeed(blinkm_addr, 5); // Slow down fade speed, so the lights will dim before power is cut BlinkM_stopScript(blinkm_addr); // turn off BlinkM script BlinkM_fadeToHSB( blinkm_addr, hue_val, 255, 0); // Start the fade out to black Wire.endTransmission(); // stop the L2C bus on arduino, so we can kill the power to the LED's, otherwise arduino freezes. delay(my_driver_cooldown); // give the psu some cool down time so the psu fan can cool the psu before we kill the power. digitalWrite(relais_pin, LOW); // un-power a relais that triggers the power-led driver Serial.print("\nPower is off, relais for psu is not active\n"); Serial.print("press the button to power up\n\n"); }// POWERDOWN - STOP

First of all, great name!! second, very good projectI just found your video, and this post, and it looks good..and now i'm trying to make it for myself..I got an homemade encoder, from a hd, and a blinkM.. Looking trough the La bougie code i saw a lot of library's that the program can't find..

Which RotaryEncoder library are you using, or do you have more information.., or a complete file ?