With parts on the way my next step was to start working on the software side of the project. Now I am a hardware guy, I know that you can do amazing things with software, and if it means less mucking around with 'Hard Logic' and greater flexibility then I am all for it. However, I often have no idea where to start when it comes to the actual code. That is one of the main reasons why I have chosen the Arduino platform for this project, for the simplicity of coding, the number of code examples available and because I don't have the facilities to spin my own PCBs at the Højskole a ready made development board simplifies the situation considerably. Another advantage with this is that I had some of the code from a previous project that I could reuse.
A couple of years back I was asked by a family member if we could do some 'Fancy Lighting' with the glass splash-back behind his stove in the kitchen of the new house that he was building, the 'fancy' solution ended up being an RGB LED strip lighting through the glass, the effect was pretty cool and has become a talking point at parties.
I wrote the original code with help from a friend and while it wasn't the most elegant it was functional and fit for purpose. I planned to reuse elements of this code, making it more elegant where possible.
The controller would have eight push buttons, four power transistors, one PIR sensor and one microphone. The intention was to build it in stages, first the pushbuttons and power transistors to provide basic control, then adding code to allow the LEDs to cross fade, next a PIR would be added and finally the microphone, other coding elements, for example a tap tempo button to control the crossfade rate, could be explored after that. The code would have to grow along with the hardware, and after many long nights, countless uploads and lots of debugging I think I have ended up with a pretty robust foundation. At this stage only the first and second stages have been implemented; basic control and crossfading, and it functions really well. The following snippet is the code in its current iteration.
/*===================[ RGBW LED CONTROLLER ]=============================================================================================
*Author: D. Blackler
*The code is designed for the Arduino Uno, it takes inputs from eight(8) momentery push buttons, one(1) microphone and one(1) PIR sensor and outputs a
* PWM signal to a length of RGBW LED strip via three(4) power transistors. The input push buttons
* are as follows:
* Button Momentery Hold
* Red Red 100% Length determines % of red in mix
* Green Green 100% Length determines % of green in mix
* Blue Blue 100% Length determines % of blue in mix
* White White 100% Length determines intensity of white
* Fade Starts cross fade cycle
* Reset Resets colour mix to all off
/*===================[ REVISION HISTORY ]===========================================================================================
* Revision 1: 14/09/2014
*-First created and formatted
* Revision 2: 17/10/2014
*-First generation functional code
/*===================[ PIN DEFINITIONS ]===========================================================================================*/
#define REDPB 2
#define GREENPB 3
#define BLUEPB 4
#define WHITEPB 5
#define FADEPB 7
#define RESETPB 8
#define REDPIN 6
#define GREENPIN 9
#define BLUEPIN 10
#define FADESPEED 15 // The higher this number, the slower the cross fade speed will be
// Initialize global variables
int FADE = 0; //Crossfade indicator initialised to 0
/*===================[ SETUP ]=====================================================================================================*/...
Read more »