0 Replies Latest reply on Mar 30, 2017 3:07 PM by jlangbridge

# RGB Wand for Codebug - mix and make

I'm getting ready to go to a school in France to show off the Codebug, a cute little design that makes development easy. There are some great examples on the element14 site, and I found an example for an RGB wand, something my 5 year old daughter loved (she put on her fairy disguise and ran around with the Codebug until the batteries drained). However, if I want to show development to kids, I need something with a little more impact. So, with the RGB wand in mind, I went and made something else.

Take a breadboard, and 3 variable resistors. For this example, I'm using 4.7K versions. Hook one end to "Power", and the other to "Ground". Do the same for all three. Now, connect the middle pin to pins 0, 1 and 2. These will be R, G and B respectively. Add a ColourStar, wire everything up with the crocodile clips, and it's time to code.

The code is simple; we will set legs 0, 1 and 2 as analogue inputs. We'll also use the CoulorStar. We create a loop, one that will run forever. On each iteration, we will read in the values of pins 0, 1 and 2, and store them into variables; R, G and B respectively. Then, in another loop, we will turn each of the ColourStar LEDs to the value found on the analogue pins. Then repeat, forever. Here's what my setup looks like:

Flash the program, and play about. With each of the variables resistors at a zero value, the LEDs are turned off. With each of the variable resistors connected to Vcc, all three colours are fully lit, and the LEDs appear white (watch it, these things are bright!). What happens when you turn on blue with a hint of red?

With this, I hope my students are going to have fun, while learning about colours, and also about programming. I'll teach them programming, they will teach me about colours, since I'm totally colour-blind (almost black and white colour vision).

The entire project took about ten minutes, hunting down the final variable resistor included. The code itself was less than five minutes, it really is that easy to program these devices. I'll keep you updated on what my students think!

A huge thanks to element14 for the "Bit by the bug" campaign!