La Bougie (blinkm via rotary encoder)

A new day, a new code:

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.

VERSION 2.5 PART 1

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

digital 5 - rotary button
digital 7 - Rotary A 
digital 8 - Rotary B
digital 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 Saturation
menu  2        : randomize colours, and some blinkm presets
holding the button very long will power off
-------------------------------------------------------------------- */


#include "RotaryEncoder.h"
#include "Wire.h"
#include "BlinkM_funcs.h"

#include <WString.h>
#include <Client.h>
#include <Ethernet.h>
#include <Server.h>


#define blinkm_addr 0x00
int my_menu = 1;                            // The first menu to start with
int my_previous_menu = 0  ;                 // To see from which menu we came
int my_option = 1;                          // The first option to start with

int my_hue = 128;                      // Default hue        at startup, which will be changed by the rotary controller
int my_brightness = 255;                // Default brightness at startup, which will be changed by the rotary controller
int 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_ value
byte bri_val;                               // This is used to transmit via the l2c blinkm command and will receive the my_ value
byte sat_val;                               // This is used to transmit via the l2c blinkm command and will receive the my_ value

int my_poweroff_timer = 4000;               // timer holding the button to power off
int my_option_timer   =  600;               // timer holding the button to change between options within menu's
int my_menu_timer     = 3000;               // timer holding the button to change between menu's

int my_hue_random= 100;                     // just to initialize, it will get random in the code
int my_saturation_random = 100;

boolean my_power = false;                   // false will eventually disable an external driver for power-leds

int my_driver_warmup = 4000;                // Delay in msec to warm up the driver for the leds
int 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-leds
int running_led_port = 9;                // a reserved port for blinking the running_led
boolean running_led_state = false;
int running_led_interval = 50;                  // a reserved counter to blink the running_led
long running_led_Millis = 0;
int when_to_randomize_counter = 0;          // counter needed to calculate when to random
int when_to_randomize = 100;                // increase to enlange cycles between randomize in menu 2, option 1. value 100 = ~ 10 seconds
long  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)


// USED FOR WEBSITE [start]
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 10, 0, 110 };
Server server(80);
#define maxLength 25
String inString = String(maxLength);
int val;
int HSB_GET;
// USED FOR WEBSITE [end]

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 operating
rotary.minimum(0);                  // the minimum value the rotary can give
rotary.maximum(255);                // The maximum value the rotary can give
rotary.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 value
pinMode(relais_pin, OUTPUT);                     // Defining the relais port to use as an output port
pinMode(running_led_port, OUTPUT);               // Defining the port to use as an output port
randomSeed(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.