The LEDs will be mounted on top of a rod which may be vertical or tilted. I want it to be one colour when vertical and gradually change as the rod tilts. The height of the LED will decrease, as the angle of tilt increases, from around 2 metres/6 feet to 0.5 metres/2.5 feet. It needs to be a cheap solution as I have to make many of them. I'm guessing that a tilt sensor might be the best way to go but they seem to be simple on/off devices in the price range I'm checking. Is there a better approach?
Consider an accelerometer. Some are very inexpensive, but unfortunately the cheapest only come in very small packages that are not feasible for manual assembly. The best I could find for manual assembly is the MXR6500MP ($4.91US from Digikey). This is a 2-axis accelerometer analog output with adequate sensitivity (with an op amp, such as LMC6482). With any accelerometer you will need a microprocessor. I favor Microchip's PIC16F886 ($2US in quantity). The '886 has an A/D converter that can convert the accelerometer signal to digital, and plenty of processing ability to make the LED drive signals. To dim the LEDs, you can use a pulse width modulation (PWM) method. The
'886 has 2 PWM modules, and you can synthesize the third from the timers in the '886. The '886 outputs have a 25ma sink/source capability, so can drive the LEDs directly. This could be a fun project!
Mike's suggestion of a multi-axis accelerometer is a good one. You could also use a multi-axis magnetometer (compass), or if your rod is rotating on a shaft or axle you could detect the shaft rotation by coupling it to a simple potentiometer or a shaft encoder. Have fun!