Archive | Crumble Projects

DIY Switches

Although the outputs (motors, Sparkles, buzzers etc) of the Crumble get a lot of love and attention, we mustn’t forget how awesome inputs are! They allow us to interact with our projects. Arguably the simplest type of input, the humble switch provides us with a digital(binary) input for the Crumble; it is either on/off or HI/LO.

Before we look at making our own switch, we need to consider what a switch is, and what it does. This will help us later on. If you already have a good understanding, then feel free to skip over the next bit.

First, let us consider a circuit – a closed loop of conductive material and electronic components through which electricity flows. The important word here is ‘closed’. Electricity will only flow when there is a clear path from positive (+ve) to negative (-ve). If we break the circuit/connection, then the electricity will stop flowing. This can be very useful when we want to control components in a circuit e.g. a buzzer or a light. We can do this by using a switch – a component which we use to control the flow of electricity.

There are all manner of switches available, from a good ol’ push switch to an illuminated key switch. But sometimes there just isn’t quite the one we want, or one we can integrate into a project how we want. A great way of solving a particular problem and thinking about how switches work is to make your own. To make something, which when interacted with in some way, will close a circuit. Not only does this give you a great insight as to how switches work, the concepts involved are perfect for meeting various Computing/Science/Design & Technology curriculum targets.

So without further ado, let us look at different ways to make switches!

First of all, let’s make a classic split pin/paperclip switch.

By moving the paperclip, we can open/close the switch. The paperclip joins together our two contacts (split pins), which are connected to the Crumble – one on a +ve output, and the other to an input (A, B or C – D is used for a Sparkle). When the connection is made, A becomes HI and the Crumble turns a Sparkle on red. When the connection is broken, the Sparkle turns off.

Our code for this is as follows. Although not the most efficient way of achieving our desired result, this code is easily extendable for our rotary switch. If A is HI, then set the Sparkle red, otherwise turn the sparkle off.

Continuing along the theme of a simple switch, lets make a ‘pressure pad’ style switch.

When pressure is applied to the top surface, the foil bridges the gap between the two foil contacts on the bottom surface (connected to the Crumble as before). This then runs the same program as before – the switch is a straight swap.

Finally, we decided that we wanted a rotary switch, with multiple outputs.

The centre arrow can be lined up with one of three outputs. Each one connects to a separate input on the Crumble. Depending on which one of the inputs is HI, the Crumble lights the Sparkle red, green or blue.

The code for this is an extension of our previous two switches, except that we check for multiple different conditions being true (inputs being HI).

These are just a few different ways of making your own switch. By taking the very basic principle of ‘bridging a gap’ and closing a circuit, you can easily let your creativity run.

If you have a go at this project, or any other, we’d love to see! Get in contact with us via emailFacebookTwitter or our Forum, and we may feature your work!

NCW Day 5 – Game Time!

Welcome to our fifth and final blogpost from our National Coding Week special. If you’ve missed any of the other four, or want to find our more about what we’re doing, and why we’re doing it, then head over here to find out more.

This final post, as mentioned previously, is all about playing a game. We are going to combine together each of our previous elements, and turn them into something playable! To recap, we’ve got the Colour Picker, the Dice, the Letter Spinner and the Countdown Timer.

Before we get into the fundamentals of the game, we are going to combine together each of our individual elements, so that at the push of a button, our game runs! If you remember, each of our projects shared the fact that they were started at the push of a button, or when the I/O pad was HI. By tweaking each project to turn an I/O pad, connected to another Crumble, to HI at the right moment, we can cause a chain reaction! To get a better sense of what is going on programmatically, lets look at our new Colour Picker code.

Notice the addition at the end of the code. We’ve set C HI, which is connected to A on the next Crumble (running the Dice program). We then wait 100ms and set it LO again.

We’ve changed each program (apart from the Countdown Timer) so that it runs the additional code snippet after it’s finished it’s main purpose. We have changed the Countdown timer code so that it doesn’t wait for another input to reset the servo, rather it resets itself after a few seconds.

To get this to work correctly, we need to have common grounds (-ve). The easiest way to do this, like we have, is to use a single power supply.

This is only one of the ways to connect your projects up.

Lets look at the chain reaction in action!

Now we come to the game, which is played as follows. The aim is to come up with as many words as you can, which are as long as the number on the dice, within the time limit (one and two may be tricky, so you could remove them). The colour at the beginning relates to a bit of a forfeit which takes place during the round. These are as follows:

  • Red – Scattergories mode. If any of your words are the same as anyone else’s, they don’t count for anyone! You need to be unique to win.
  • Green – Hand switch. Swap your usual writing hand, for your non-dominant one.
  • Blue – Shout it out. Every time you write down a word, you have to shout it out.
  • Yellow – Normal. No bizarre rules, just write down as many words as you can.

Let’s look at an example.

Here we’ve ended up with green, five and G. This means that we need to write as many five letter words as we can, that start with the letter G, in 30s. But we have to do it with our non-dominant hand, so in my case I would swap to my left hand to write with.

And there we have our game ready to play! Clearly you aren’t limited to this version of the game. There’s a plethora of possibilities out there using these examples or combinations of your own.

If you have a go at this project, or any other, we’d love to see! Get in contact with us via emailFacebookTwitter or our Forum.

NCW Day 4 – Countdown Timer

Welcome to our fourth blog post, in a series of five, in celebration of National Coding Week. If you haven’t already, take a look here to find out more about what we’re doing, and why we’re doing it.

The next part of our game is going to be a countdown timer. The aim of this project is fairly self explanatory. Our game requires a time limit, so what better way to keep us within the time limit than with a timer not dissimilar to the one from Countdown!

For this you will need:

For the eagle-eyed amongst you, you may realise that we have already done a Countdown Clock Project. This is going to be an updated version of it, but we will go into less depth with the programming. If you are unsure of why we did something, go and check out the original post for help.

To begin with, we are going to connect together the components. Connect the +ve and -ve on the battery box to the respective connections on the Crumble (left hand side). Make sure to keep the batteries switched off for the moment.

Now we are going to connect our servo. This requires a +ve and -ve connection, which we can take from the right hand side of the Crumble, and then one I/O pad; we’ll use D, to keep the wiring neat!

To get the basic servo-powered timer working, we need to think about what we are trying to achieve. Let’s say that that we want the timer to last for 30 seconds. During this time, the servo needs to travel 180 degrees, from the top of the clock face, to the bottom. Therefore our servo needs to travel 180/30 degrees (=6) every second. We can achieve this using a variable and a loop. We set our servo to 90, then every second, we subtract 6 from the servo angle and re-set it.

To make this switch controlled, we can use a similar method to our previous NCW projects. Within a loop, we wait until A is HI before starting our timer code. We then have another ‘wait until A is HI’ after our main timer code, which works in such a way so that the servo resets and waits to be started again. You’ll notice the extra wait statement – this allows the servo to ‘reset’ before you press the button to start it again.

Given that it is unlikely that the players will be looking at the clock, we can also add in a buzzer to give us an audible cue as to how much time has passed. This will also help ramp up the pressure, making the game more exciting! We’ve connected the buzzer to B, and to the negative pad on the battery box. This means that when we set B HI, the buzzer will sound.

To use this within our program, we need to turn on the buzzer, and turn it off again in between setting the servo angle (our original timer code). The total amount of time we need to be waiting, still needs to be equal to 1 second (buzzer on for 0.2 seconds, and off for 0.8). Notice where we have turned the buzzer on towards the end. This sounds the buzzer continuously until the clock is reset. This is useful to know when the time is up!

We now have a working 30s timer! Although the servo isn’t very useful at the moment, so we are going to embed it with our Countdown Clock Template. For instructions on putting this together, head back to our original project page.

And there you have it, a 30s Countdown timer!

If you have a go at this project, or any other, we’d love to see! Get in contact with us via emailFacebookTwitter or our Forum.

NCW Day 3 – Letter Spinner

Welcome to our third blog post, in a series of five, in celebration of National Coding Week. If you haven’t already, take a look here to find out more about what we’re doing, and why we’re doing it.

The next part of our game is going to be a letter spinner. The aim of this project is to randomly choose a letter of the alphabet, spread around, by way of a large spinning arrow. We will borrow from the foundations of our Probability Spinner Project and tweak it.

For this you will need:

For starters, we are going to connect together the components. Connect the +ve and -ve on the battery box to the respective connections on the Crumble (left hand side). Make sure to keep the batteries switched off for the moment.

Now we are going to connect a motor, with the pulley attached. You can use either motor connection on the Crumble, but we’re using motor 2. Connect the red lead of the motor, to the + on the motor pad, and the black to the – .

Getting our motor to move is simple, as is getting it to stop, but we want to make it spin for a random amount of time. To do this, we can use the ‘random _ to _’ block; a common occurrence throughout this blog series. When the Crumble receives power, we will give ourselves 2 seconds to move our hand away, then we will turn the motor forwards. We will wait a number of milliseconds, between 3000 and 9000, and then stop the motor.

To make the spinner easier to use, we can use a push switch to trigger the spinner. This connects to a + connection, and an I/O pad (A, B, C or D).

As with our previous posts we are going to ‘pause’ the program and wait until the input (D) is HI’. Once the switch is pressed, the program continues and our spinner code will run. All of this will then be inside a loop, to allow for infinite letter choosing! Or until the batteries run out, or we get bored.

Although this spinner is perfectly adequate, to make it more realistic, we want it to slow down gradually. We are going to add a variable called ‘Speed’, which will start at 100 (%). When the spinner is due to stop, we will run a loop which subtracts varying amounts from ‘Speed’, bringing the motor to a gradual-ish stop.

Hint: we use the condition ‘if speed < 1’ as the speed value may not equal 0. If we didn’t, the value could become negative and the motor would begin speeding up in the other direction!

And there we have a our letter spinner ready to rock!

If you have a go at this project, or any other, we’d love to see! Get in contact with us via emailFacebookTwitter or our Forum.

NCW Day 2 – Dice

Welcome to our second blog post, in a series of five, in celebration of National Coding Week. If you haven’t already, take a look here to find out more about what we’re doing, and why we’re doing it.

The next aspect of our game involves a random number selection, and in our case, digital dice. There are a few ways you could go about this, but we are going to use the Matrix display to represent the dots, as it is already in a nice grid.

For this you will need:

First of all, we are going to connect together the components. Connect the +ve and -ve on the battery box to the respective connections on the Crumble (left hand side). Make sure to keep the batteries switched off for the moment.

Next, we need to connect the Matrix Display. Connect the remaining +ve and -ve on the Crumble to the corresponding connections on the Matrix board. Looking at the Matrix board with the text the correct way up, it’s the pads on the left-hand side. Then connect D from the Crumble to the board – notice the direction of the D arrow, it should point away from the Crumble. If you are using the Matrix Pixelator, you may need to look carefully at which way around your board is in the holder.

Before we come to write our code, we need to work out what our numbers (or spots) will look like. It can be a good idea to plan this to save confusion later on.

Now we come to writing our code. This program is similar to the colour picker from yesterday, but instead of assigning a single colour to a value, we are going to assign an ‘image’; or multiple Sparkles. Lets start, as before, with two choices. We’ll look at choosing either 1 or 2. First of all, lets get our variable set up.

Now we can add a condition in. Remember that we can use the ‘IF ELSE’ statement as our options are mutually exclusive; our ‘RandomNumber’ cannot be one and two at the same time! If the generated number is one, then we want the Matrix display to show one, otherwise the generated number must be two and so we want to display two on the Matrix. We’ve also turned off all of the Sparkles at the beginning, which makes sure that our Matrix is ‘reset’, and we’ve got a wait statement, which gives us time to move our hand away from switching on the power.

Now we want to extend our code, as before, to have as many options as we require (6), and so that we can choose our number at the push of a button. Wiring in a switch is simple. One side connects to a free +ve connection, and the other to an I/O pad on the Crumble – we’ll go for A.

Using the switch within our program is easy. Put your code within a ‘do forever’ loop, so that it runs indefinitely whilst the Crumble is powered, and then we can use a ‘wait until’ block. This behaves like a pause in our program, so that it won’t move on until the condition is met, which in our case is when the button is pressed and A is HI. The wait statement from earlier comes in useful here too, as does clearing the Sparkles.

And there we have our digital die, ready to roll (excuse the pun)!

If you have a go at this project, or any other, we’d love to see! Get in contact with us via email, FacebookTwitter or our Forum.

NCW Day 1 – Colour Picker

Welcome to our first blog post, in a series of five, in celebration of National Coding Week. If you haven’t already, take a look here to find out more about what we’re doing, and why we’re doing it.

The first aspect of our game is going to be a colour picker. The aim of this project is to set a Sparkle to a random, but predetermined colour. Or in other words, choose from a set choice of colours (that we have programmed). This could then go on to be used to pick an option from a list or a team to take part etc.

For this you will need:

First up, we are going to connect together the components. Connect the +ve and -ve on the battery box to the respective connections on the Crumble (left hand side). Make sure to keep the batteries switched off for the moment.

Next, connect your Sparkle. Connect the remaining +ve and -ve on the Crumble to the ‘in’ on the Sparkle (the D arrow should be pointing to the right). Then connect D from the Crumble to the Sparkle, taking care to get the direction correct, as previously mentioned. Use the diagram below if you’re unsure.

Now we come to writing our code. To begin with, we are going to randomly choose between two colours. To do this, we want to think about assigning each of our colours a number – starting from zero e.g. Red = 0, Green = 1.

At the the beginning of our program, we want to choose a random number within the range of our list. So either 0 or 1. Once we have chosen the number and ‘remembered’ it (by assigning it to a variable), we can work out what colour to set the Sparkle.

This is achieved by a series of selection (or ‘IF’) statements – basically questions. In English, it would be ‘If the random number is 0, then make my Sparkle red’. Notice the wait statement – this just allows us time to get our hand away from the switch, but it also gives the illusion that the Crumble is ‘thinking’. Also notice where we turn the Sparkle off at the beginning. Whilst the Sparkle has power, it remembers the colour it was last told to be. Although at the moment we are using the battery pack to switch on and off, we will need this in the future, so it’s good to put it in now.

We could repeat this for the other colour, changing the numerical value and the colour of the Sparkle, and this works just how we want it to.

However, there is a bit of redundancy within our code. As our two conditions (if RandomNumber = 0, and if RandomNumber = 1) are mutually exclusive (they can’t both be true), we don’t need to check the second condition. If the ‘RandomNumber’ doesn’t equal 0, then it has to equal 1 (as long as the random number generation is correct). Therefore, the best way of writing this code is as follows.

From this point on, it should be easy to see how you would extend this code to choose between even more colours! See if you can choose between 4 different colours?

We have a working colour picker, but at the moment it only works once. So, instead of triggering our program by powering the Crumble on, we can add a push switch instead. This way, we can repeatedly generate our colour! If we connect up our switch to A (and a +ve connection), it’s really simple to add in the code to start our colour picker.

We have used the ‘wait until’ block, which halts the program until A is HI (the button is pressed). Our wait statement now also gives us time to remove our finger from the switch. If it wasn’t there, we could repeatedly choose a random colour, and it would be impossible to use. We’ve also put our code inside a ‘do forever’ loop. This runs the code indefinitely, whilst the power is on. Turning off the Sparkle is now really useful! Not only can we see the new colour when the Sparkle lights up, there is no confusion if the colour picked is the same as last time.

And there we have our colour picker!

If you have a go at this project, or any other, we’d love to see! Get in contact with us via email, FacebookTwitter or our Forum.

National Coding Week – Blog Special

Next week is National Coding Week, and we thought to celebrate this, we would release a series of blogs dedicated to a project theme. This time we have chosen ‘games’. Each day there will be a new blog post detailing how to create a simple game-related project. Then at the end of the week, each one of these projects will connect together to form a game, which we will go into more detail on Friday.

As it stands, here is our current plan of action: Monday – colour picker using a Sparkle; Tuesday – dice using a Matrix display; Wednesday – letter spinner; Thursday – audible countdown; and Friday – Playing the game!

Each individual blog (apart from Friday) aims to provide you with a small project that you can do discretely, and then if you complete each one, you will be able to combine the smaller projects into a form of game.

Like other initiatives, National Coding Week is designed to encourage people of all ages to try something new, around the theme of coding/programming. There is a massive emphasis that not just schools get involved, but individuals and businesses too! You can find out more on their website.

If you have a go at any one of these projects, we’d love to see! Get in contact with us via email, FacebookTwitter or our Forum.

NCW Day 1 – Colour Picker

Welcome to our first blog post, in a series of five, in celebration of National Coding Week. If you haven’t already, take a look here to find out more about what we’re doing, and why we’re doing it. The first aspect of our game is going to be a colour picker. The aim of this […]

NCW Day 2 – Dice

Welcome to our second blog post, in a series of five, in celebration of National Coding Week. If you haven’t already, take a look here to find out more about what we’re doing, and why we’re doing it. The next aspect of our game involves a random number selection, and in our case, digital dice. […]

NCW Day 3 – Letter Spinner

Welcome to our third blog post, in a series of five, in celebration of National Coding Week. If you haven’t already, take a look here to find out more about what we’re doing, and why we’re doing it. The next part of our game is going to be a letter spinner. The aim of this project […]

NCW Day 4 – Countdown Timer

Welcome to our fourth blog post, in a series of five, in celebration of National Coding Week. If you haven’t already, take a look here to find out more about what we’re doing, and why we’re doing it. The next part of our game is going to be a countdown timer. The aim of this project […]

Growing Plants Under LEDs

This project is one of the activities that makes up part of the Global STEM Award’s coding route.

In the future, it may be the case that the Human race begins to settle on another planet – probably Mars. We will inevitably need to grow food, as you can only carry so much, and with a journey taking around seven months, emergency rations wouldn’t arrive quick enough!

Scientists are certain that areas of Martian soil do contain the right levels of nutrients to grow plants, but unfortunately the climate isn’t conducive to horticulture. At the height of summer, temperatures near the equator only just reach 20 deg C. Not too bad – but over night they still plummet to an eye-freezing -73 deg C. Just a reminder, this is Summer. At the equator. The warmest part of the planet!

So if growing plants isn’t an option outside, where else can you grow them? Well it would be possible to set up greenhouses, but they would need a lot of protection and heat to keep the plants going. You could also bring the plants ‘indoors’ – setting up growing stations mixed in with living quarters, the environment would already have to be the right temperature, and the plants will assist with air purifying. Another option would be to head deep underground, where geothermal warmth could be used, but then you are posed with another issue – plants need light. Where is this going to come from?

Using the Crumble, along with some Sparkles, we’ve had a look into growing plants under artificial lights. We initially set up a tester investigation to see whether or not there would be a difference, and whether the plants would grow at all! We decided to use some cress as it is easy to grow, and it has a short germination time. We left one pot in the sunlight, another covered up, and another three covered, but with a Sparkle shining inside (one Red, one Green, and one Blue).

Our initial test was very positive, so we have upscaled the investigation. We know that plants grow well in the spectrum of light produced by the sun as they have likely adapted themselves to do so. But there is a question as to whether they prefer a certain colour of light. We are going to look at how well cress grows under different colours of light.

dav

Our first step was to create an open-fronted enclosure for the pots (which we’ll come to later). As we wanted to grow a larger amount of cress, we have used two Sparkle Batons, but if you wanted to do this on a smaller scale, with lots of groups, you could easily use some paper cups and individual Sparkles. The spacing was set so that there were two Sparkles lit with each colour, on each baton, so four in total. This means that there are two unused Sparkles on each baton. The Sparkle Batons are loosely held in place, with a piece of card and some split pins. This is enough to prevent it moving.

Once we had our container made, we decided to draw and 3D print some custom pots and water trays, to get the most out of our growing space. We filled these with some damp compost, and sprinkled 0.2g of seeds across each one.

We then put the filled pots into our divider, and connected our Crumble. The code running on the Crumble isn’t too difficult. Put simply, we are turning on the Sparkles we need, to the colours we want. After a set amount of time, we turn them off (to simulate night time) for another period of time. The amount of time that we wait is determined by how many hours we want the Sparkles to be on for.

Once set up, we switched on the Crumble and waited. During the course of the investigation, we routinely inspected the plants and made sure that they hadn’t dried out. It is worth noting that we set up our test in a dark cupboard, to make sure that we were only using the Sparkles as a light source.

We had a go at capturing the first few day’s of growth. Each fade represents the night time and is shortened as you cannot see anything!

When the seed is in the soil, you don’t get to see the moment it germinates, so we thought that we would have a go at capturing that moment. Notice how the seed swells as it hydrates, before it splits open and starts growing.

Which worked the best can be difficult to determine – you cannot just go by a plant’s height. When a seedling doesn’t get enough light, it rapidly grows taller, in search of light (often described as leggy) and it takes on a rather yellow colour. A healthy cress plant shouldn’t be floppy or spindly, and it shouldn’t have any yellow tinge to it at all. In fact, working out which is best is rather subjective, but the easiest way is to see which one ‘looks the healthiest’.

To work out which colour of light was the ‘winner’, we took into account the height of the plant and looked at how green the leaves were. We took a picture, with no filters or effects, and in natural daylight, which we then uploaded into an image editing program. Using the software, we used the colour picker to work out the green RGB level . By taking an average of 4 different leaves from each section, we got the following results: Green – 87.25; Blue – 95.25; and Red – 130.25. This tallies with our visual analysis – which pretty much tied the Red and Blue plants. Unfortunately, we have ended up with a large amount of soil on top of the Red cress, making it harder to see.

Blue – Red – Green

From our first investigation, with only a few seeds, we found Blue light to be the best, and Green to be the worst. So the common result that we have found is that Green is the worst light to grow under.

This isn’t the only way you could combine plant growing with the use of Sparkles. You could try combinations of colours, more/less ‘night’ etc. You could even use low-power heating devices like a peltier cell to adjust the temperature of the soil.

If you have a go at this project, or any other, we’d love to see! Get in contact with us via email, or on FacebookTwitter or our Forum.

Programming challenge: a temperature-sensitive light.

This project builds on the previous post, where we explained how to set Sparkle colours using the “RGB” block:

Sparkle RGB block

It was inspired by the type of night-lights that are available for babies’ bedrooms, where the colour of the light indicates to parents if the room is getting too hot or too cold.

We want the Sparkles to display predominantly “cool” colours if the room is too cold and “warm” colours if it is too hot. As we are using the matrix display, it would also be nice to have a pretty “twinkling” effect.

The block which randomly changes the colour of each Sparkle in the matrix display

The program is, therefore, based around the block, above. The colour of each Sparkle in the array is updated, randomly. The level of green light also changes, randomly. If the value of “red” is low and the value of “blue” is high, the Sparkle colour will vary between blue and cyan (depending on how bright the green light is) while if “blue” is low and “red” is high, it will vary between red, orange and yellow.

A previous night-light project shows how to connect up the Crumble, battery pack and Sparkle matrix display. The input from a light-dependent resistor (LDR) was used to control whether the lights are on or off. In this project, instead of the LDR, we are using a thermistor (a resistor whose resistance varies depending on temperature). You can simply attach a croc clip to each “leg” of the component but, to make it a bit easier to handle, we have soldered ours onto a “crumbliser”

The first thing we need to do is calibrate the input, i.e. work out what temperature the resistance of the thermistor corresponds to. The thermistor is connected to “A” and “B” on the Crumble: “A” will be the output and “B” will be the input. The following program allows us to monitor the value of “B”. As it depends on temperature, we have assigned it to a variable called “t”.

Something I learnt during the course of this project is that, if you want to calibrate an analogue input, it is better to connect it across 2 of the Crumble I/O pads (A,B,C & D) as we have done, here, rather than connecting one pad to the Crumble and the other directly to the “+” pad on the battery box. This is because the voltage level from the battery box can vary, whereas the Crumble itself outputs a fixed voltage.

We then immersed the thermistor in hot water; in iced water; put it outside; and, finally, my 6-year-old held it in his hand. We watched how the value of “t” changed (in the “Variables” menu of the Crumble software) and my 9-year-old made a table and then a graph of the results.

Based on this investigation, we decided that the red emitter should be off (0) when t = 85 and fully on (255) when t = 170. (Ice water and boiling water being a bit too extreme in this case!) The blue emitter can then simply be the inverse of this (i.e. 255 minus the value “red”).

Our table of results and graph

I briefly explained the formula for a straight-line graph (y = mx + c) and “we” determined that m = 3 and c = -250. We then input these numbers into the Crumble program in order to convert the value of the input “t” into our outputs “red” and “blue”:

We also used two “if” blocks to set limiting conditions to prevent the value of “red” (and, hence, “blue”) going higher than 255 or lower than zero.

The completed program is:

Crumble program for our temperature-controlled night-light

The program is inside a “do forever” loop so the colour of one random Sparkle in the array is changed every 100 ms.

It is difficult to capture the different colours on camera, but here is the finished night-light (mounted in the Sparkle matrix pixelator) at three different temperatures:

Aaah…. just right!

Science with the Crumble: Colour mixing

Red, Green & Blue:

Can you make your Sparkle baton display a rainbow? The simplest way is to set each Sparkle colour, in turn, with the computer’s colour picker:

Simple “sparkle baton rainbow” program
Sparkle baton displaying a “rainbow”

But do you know how a Sparkle LED can display all these colours? The primary colours of light are red, green and blue (RGB). Each Sparkle has a red, green and blue LED inside and the relative brightness of each of these determines the colours that your eyes see. Mixing equal amounts of red and green gives yellow; green and blue make cyan; and blue and red make magenta. Red, blue and green mix together to make white light.

Under the “Sparkles” menu in the Crumble software is a block which allows you to set the level of each RGB emitter (0 is off; 255 is maximum brightness). The following program will, therefore, display the primary and secondary (yellow, cyan and magenta) colours along the baton.

Primary & secondary colours

If you are interested in seeing how other colours are made, the colour picker will tell you the RGB values of the current colour and allow you to change them, via sliders or by typing the value. Here, for example, we have chosen orange:

The red emitter is fully on (255), green is at half-brightness (127) and blue is off. If we now increase the blue to fully on, we get pink:

Note: this is the MacOS colour picker, Windows may look different but should still have the same information. You might also notice a Hexadecimal colour code (Hex code #FF7F00): I won’t go into more detail, here, but if you are interested in computer programming and/or graphic design you should investigate this further. 

Colour & the Human Eye:

We can use the block

to show that equal amounts of red, green and blue light mix together to make white light. The program, below, though, also demonstrates our eyes’ persistence of vision.

Sparkle cycling between red, green & blue

The last Sparkle on the baton (“sparkle 7”) cycles round the primary colours more and more quickly. The time interval starts at y=1000ms then halves after every z cycles while the number of cycles starts at z=1 and then doubles. As the LEDs cycle faster our eyes will first perceive a flickering and then a steady white light. You can show, though, that the LEDs are still cycling, even when the white light appears steady, by rapidly moving the baton from side to side: now our persistence of vision lets us see separate red, green, and blue “lines”.

Further Colour-mixing Activities:

Can you use your colour mixing knowledge recreate the “rainbow” display, above, but now get it to scroll along the sparkle baton? This diagram may help:

RGB colour mixing diagram

If you have a sparkle matrix, you can experiment with more colour effects. For example, what do you think the following program does?

Or pick your favourite colour(s) to draw a picture:

Sparkle matrix displaying a pink heart.
Happy Valentines Day!

The next blog post will explore using variables as RGB values and show how to use an input to control the Sparkle colours.