Tag Archives | Sparkles

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.

A Crumble-Powered Automatic RGB Nightlight

Sometimes inspiration can be hard to come by. We have known for a while that we’ve wanted to make a nightlight, but didn’t know how to make it different from all the rest.

We stumbled across an interesting video on YouTube which peaked our interest and gave us the inspiration we needed. How awesome would this nightlight look if we added a whole heap of Sparkles (a Matrix display) and gave it a Crumble kick?!

The Crumble-powered RGB nightlight was born.

Although this post will be a whistle-stop tour of the process, when we have our finished Sparkle Matrix display, we will definitely work on some in-depth instructions and teaching resources.

We started off by preparing a cardboard box, by removing all of the sellotape. We then glued it back together, to make sure that it was sturdy.

We then cut the faces of the box off, leaving a border. This would give us the frame for our light.

After this, we drew some straight lines on a word document and printed off 5 copies. We then trimmed each sheet so that it could be glued inside the 5 faces of the frame.

When we had finished our light, we decided that we didn’t like the bare cardboard, so we used a silver permanent marker to give it a metallic look.

Wiring up the Crumble was simple enough.  After connecting the Sparkles (inside the shade), we connected a light-dependent resistor (LDR). One end connected to a + output, in this case from the batteries, and the other end connects to an input (A, B, C or D). We used A.

It’s really easy to use an LDR with the Crumble. Take a look at the following program. When the analogue value of the LDR (we’ve renamed it to be helpful) is above 90, turn all of the Sparkles off,  if it isn’t above 90, and therefore less than it,  then turn the Sparkles on.

To get the nice RGB effect, we have cycled through the red, green and blue values.  This graph shows how increasing or decreasing the different values gives us different colours. Doing it in this particular order gives us a lovely rainbow effect!

We have created variables called Red, Green and Blue. We then set the corresponding red, green and blue Sparkle values to our variables. We have cycled up/down the RGB values to give us our transition of colours. Each time the colour changes, we check to see the value of the LDR, and whether or not to turn the lights on/off.

And here is our RGB nightlight, in all of its glory! When the Sparkle Matrix gets finalised, we will create some more in-depth teaching resources for this project, as it’s easy to make and really satisfying.

Christmas has arrived!

Our first proper Christmas since we moved in to our new building with Mindsets. We’ve decided to mark the occasion with a suitably decorated tree!

We connected 20 Sparkles and a Sparkle Baton together using croc-leads. We then wrapped these around the tree, with the Baton on the top. The croc-leads are almost a decoration in themselves!

The Crumble is connected to a Raspberry Pi, which is connected to our network, meaning we can remote-desktop in and change the lights! It’s pretty much an Internet of Things Christmas tree.

We decided to add our big red button near the base of the tree, to allow the user to cycle through the light sequences. The code runs a light sequence, and waits for the button to be pressed before moving onto the next sequence.

We decided that the tree was a bit bland, especially during the day time, so we added a few more decorations to it.

And there we have it, our IoT Christmas tree, ready to be programmed by anyone in the office.

Science with the Crumble: Test your reactions

HYPOTHESIS: Humans react more quickly to something they hear compared to something they see.

In order to test this hypothesis, we used:

  • Laptop with Crumble software installed
  • Crumble controller & Sparkle baton
  • Crumble-friendly battery box; 3 AA batteries
  • Croc-leads and a micro-USB cable
  • “Crumble-friendly” switch and buzzer

The Crumble, Sparkle baton, switch and battery box are connected in the same way as the last reaction timer project (although the switch is connected to input A, rather than B). The program, however, is much simpler:

At the start, all the Sparkles are turned off. The Crumble waits for a random period of time (between 2 and 6 seconds) and then begins lighting the Sparkles in quick succession (every 50 milliseconds). The aim of the game is to press the switch as quickly as possible. Note: you have to hold down the switch until you have read your “score”. When the switch is released, the game restarts. Joseph & I discovered that, after a bit of practice, we could consistently press the switch after 4 or 5 Sparkle LEDs had lit up (i.e. after 150-200 milliseconds). 

In order to test whether we could react more quickly to a sound, a buzzer was then connected between “output B” and “Ground” (a “-” pad on either the battery box, or the right-hand side of the Sparkle baton). The program was modified so that the buzzer turns on at the same time as the first Sparkle LED:

For a fair test, you have to close your eyes while playing – but remember to open them and read your score before releasing the switch! Now we found that we could press the switch after 3 LEDs were lit (100 ms). 

So, our small sample does support the hypothesis, above. Further reading suggests that humans react even faster to touch-stimulus: can you think of a way to measure that with the Crumble? If you do the experiment with a larger group, let us know your results and we will publish them, here!

Programming challenge: Traffic lights

IMG_1538We used:

  • 1 laptop with Crumble software installed
  • Crumble controller & Sparkle baton
  • Crumble-friendly switch & ultrasonic distance measuring sensor
  • 1 Crumble-friendly battery box; 3 AA batteries
  • Croc-leads and a micro-USB cable

The traffic light sequence can be programmed to run on a single Sparkle (change all the Sparkle commands in the program below to read “set sparkle 0 to..”), but using 3 chained together or, as here, a sparkle baton is more “true to life”. The traffic lights are set to be the last 3 sparkles on the baton (index numbers 5, 6, and 7 being green, amber, and red, respectively). The program is shown below:

traffic_lights

The sequence simply repeats every 3 seconds, but we can add a switch (here connected between the +ve battery terminal and Input A) to trigger the sequence. In the program below, the green light stays on until the button is pressed. 

button_cross

The program was then modified further so that the sparkle at the other end of the baton (index number 0) functions as a “pedestrian crossing”. When the “traffic lights” are green the pedestrian crossing is red. When the button is pressed the traffic lights cycle through amber to red and then the pedestrian crossing sparkle changes to green. After 5 seconds the pedestrian crossing sparkle changes back to red and the traffic lights continue through red-amber to green.pedestrian_cross

For the final challenge we also added an ultrasonic distance sensor with its “trigger” (T) connected to input “C” on the Crumble and “echo” (E) connected to “B”.

As in the program above, the button triggers the traffic lights to change to red. The “pedestrian light” (i.e. Sparkle 0) then remains green until the ultrasonic distance sensor detects a “car” approaching (in this case represented by a hand waving less than 4cm away). The “car” triggers the pedestrian crossing to turn red and the traffic lights to change to green.

Screen Shot traffic_ultra

Unfortunately, the resulting tangle of wires is not very attractive. (Note: I have used the “power out” pads on the Sparkle baton as power inputs for the ultrasonic distance sensor.)

Next challenge: construct something to hold the baton vertical and the ultrasonic module in the right position to detect a lego car!

FullSizeRender-3

Programming Challenge: Reaction timer game

This challenge involves making a reaction timer game with a Sparkle Baton. The aim of the game is to press the button when you see a green light. We used:

  • 1 laptop with Crumble software installed
  • Crumble controller & Sparkle baton
  • 1 Crumble-friendly battery box; 3 AA batteries
  • Croc-leads and a micro-USB cable
  • A switch (check out our new Crumble-friendly switches!)

Connecting the Crumble

The Sparkle baton is connected in the same way as a single Sparkle: `+’, `-‘ and `D’ on the right-hand side of the Crumble connect to their equivalent pads on the left-hand side of the baton. The switch is connected between the +ve terminal of the battery box and input B on the Crumble (see photo).

Reaction timer game

Programming the Crumble

The program was developed and refined in several stages. First, I wanted a lit LED to “travel” backwards and forwards along the Sparkle Baton: Red_travellingThe variable “t” is the index number of the Sparkle. The variable “u” switches between +1 and -1 every 8 steps, so the “let t=t+u” command increments the Sparkle number from 0 to 7 then decrements it back to 0. At each step, Sparkle “t” is set to red for 100 milliseconds. This whole sequence is placed inside a “do forever” block.

Now, as the red light travels back and forth, we want just one of the Sparkles to turn green, instead. The “set sparkle ‘t’ to red” block is, therefore, replaced with an if-else statement, which changes Sparkle number 3 to green: if_block

The program now needs to respond to user input: the aim is to press the button when you see the green light. Inside the “do forever” loop, we nest a “do until B is HI” loop.

full_prog2When the button is pressed, the program will pause until it is released (“wait until B is LO”). If the user has succeeded in pressing the button when the green LED is lit they have “won”.

In order to emphasize this, a “victory flash” is now inserted: if “t=3” when the button is pressed (i.e. if the Sparkle is green) then all the Sparkles flash green 3 times before the program continues.

victory_flash

In order to increase the challenge, a variable “time” was created, which determines how quickly the Sparkles turn on and off. Initially, this is set to 300ms and it decreases by 50ms for each successive “correct” push of the button. If the button is pressed at the wrong time, however, the time is reset.

PastedGraphic-6

Can you improve on the game? Ideas:

  • Is there a potential problem if the variable “time” becomes negative? Would it be better to decrease it proportionally rather than by a fixed number of ms?
  • Can you keep track of the “high score” by counting the number of successive, correct button pushes and flashing the same number of Sparkles?
  • What if the green Sparkle is in a different position each time? (Hint: use the “random” operator.) Does this make the game more challenging?

Victory flash

At full strength, the Sparkles are too bright to look at for long periods of time. When writing and debugging programs using Sparkles I usually cover them with (e.g.) one or two sheets of paper.

 

Crafty Crumble Creations: When Santa got stuck up the chimney!

This year our Crumble Christmas decoration uses a servo to control an “animatronic” Santa leg stuck in a chimney decorated with twinkling lights.

We used:

  • 1 laptop with Crumble software installed
  • Crumble controller; a flexible strip of 30 Sparkle LEDs and a micro Servo (both with crumblisers attached)
  • 1 Crumble-friendly battery box; 3 AA batteries
  • Croc-leads and a micro-USB cable
  • Cardboard blocks, cotton wool balls, cardboard; red and black paint; sellotape & PVA glue

Making the Chimney

The Chimney is made from some sturdy, red cardboard building blocks, that we already had at home, with cotton wool balls stuck on for the “snow”. Santa’s leg is cut out from a cardboard box, painted red and black, with more cotton wool balls as a fur trim. The turning part of the servo is sellotaped onto the back of the leg (excuse the Stormtroooper: we used the box from a Star Wars toy) and the body of the servo is taped onto a smaller yellow block that sits behind and inside the chimney. The Crumble and battery box also rest inside. IMG_9899IMG_9900IMG_9885  

Connecting the Crumble

The Crumble was connected to the battery box with croc-leads and to the computer, using the USB lead. The micro-servo has three connections: power (“+”, “-“) and “control” (labelled “S” on the crumbliser). The power pads were connected to the second set of pads on the battery box and “S” was connected to the Crumble’s pad “C”. The Sparkle strip was connected to “+”,”-“, and “D” on the right-hand side of the Crumble and then wrapped around the base of the chimney. IMG_9897

Programming the Crumble

The servo control block needs to tell the Crumble which output the servo is connected to (in this case “C”) and the angle to set the servo. As this is an absolute, rather than a relative number, we had to do a bit of experimenting. Eventually, we determined that the servo needed to move between 65 and 85 degrees. To slow down the transition, we used a loop which steps the servo 1 degree every 60 milliseconds and a variable “x”, which alternates between 1 and -1, to make it move back and forth. Screen Shot 2015-12-15 at 18.19.04We wanted the Sparkle strip to change colour at the same time as the servo is moving. As there are 20 steps in the loop to move the servo, the simplest way to do this was to use only 20 of the Sparkles. We defined a variable “sprk” to be the index number of the Sparkle. Every time the loop is executed, Sparkles 5 to 25 are set to red, in turn. Variable “x” is used to set the adjacent Sparkle to green. Once we were happy with the effect, we disconnected the Crumble from the computer and placed our decoration on the fireplace. Screen Shot 2015-12-24 at 12.38.51 Can you improve on this and work out how to thread two programs together to use all 30 Sparkles? Merry Christmas!!

Crafty Crumble Creations: A “police” helmet.

Whenever our 2-year-old finds something with a flashing light on it, he holds it on top of his head and runs around shouting “nee-nah nee-nah”. I decided we would make a flashing helmet, using a variable to set the Sparkle colour and brightness in the Crumble Software.

We used:IMG_9210

  • 1 laptop with Crumble software installed
  • Crumble controller & Sparkle
  • 1 battery box with croc-clip attachments; 3 AA batteries
  • Croc-leads and a micro-USB cable
  • A switch/Switch Crumb
  • Plastic dome; glue; tissue paper; blue paint; cardboard; & sellotape

Connecting the Crumble

Screen Shot 2015-05-18 at 16.49.34This diagram shows one way of wiring up a Crumble, battery box and switch. The switch is connected to Pad “A” on the Crumble and to the +ve terminal of the battery box. By default, the input pads are at zero Volts (“low”). When they are connected to the batteries they receive 5 Volts (“high”).

In this case, when the switch is pressed, input A is connected to the batteries. In the software, therefore, we can use the “Wait until A is Hi” block to tell the Crumble what to do when the switch is pressed.

The croc-leads on the right-hand-side of the Crumble connect to a Sparkle (see previous blog posts)

IMG_9053The photo, left, shows the Crumble and Sparkle connected with a standard push-to-make switch. There are a couple of problems with this set up, though. Firstly, 2 IMG_9056croc-clips have to connect to the top-left “power-in” pad on the Crumble. Also, the tips of the two croc-clips connected to the switch are very close (see right) and can easily short-circuit.

IMG_9061A tidier soloution is to use a Switch Crumb (the one pictured is designed and sold by 4tronix ). This has pass-through power lines, like the Sparkles, meaning it can be connected in line with the battery box and the Crumble.

A pad at the bottom of the Crumb connects to an input on the Crumble (the yellow wire in the picture), in this case to Input A.

Programming the Crumble

Screen Shot 2015-05-18 at 15.25.18Within each Sparkle there are actually 3 LEDs: red, blue & green. Their relative brightnesses are varied to create any colour from the visible spectrum. The RGB Sparkle block (below) allows us to precisely control the colour, by setting each of the LEDs to a value between 0 (off) and 255 (maximum brightness). In this program we keep red and green at 0, only changing the blue.Screen Shot 2015-09-19 at 08.37.25

 

The Crumble program used is shown above. It continuously checks to see if Input A is high (i.e. if the switch has been pressed). When it is, a loop is executed five times. This gradually increases the brightness of the blue LED within the Sparkle then decreases it (by incrementing the variable “t” from 0 to 200 then decrementing back to 0).

Constructing the HelmetIMG_9191

IMG_9197IMG_9204

IMG_9211

The plastic dome came from a supermarket package of profiteroles. A hole was cut in the top so the lid of a fabric softener bottle could be inserted. We glued bits of torn tissue paper all over the plastic (a la CBeebies “Mr Maker”) so that it could be painted blue.

The Sparkle was positioned so that it shone up into the the bottle top and the rest of the electronics was sellotapIMG_9205ed into the dome then covered with a circle of card, leaving the switch exposed.

I was planning to construct some sort of headband, attached to the bottom of the dome, with the switch mounted on it like a badge. The two-year-old, though, had already decided we were done. After that, he was never still enough for me to take a better photo than this (see right), so I think I can claim the project was a success!

DISCLAIMER: Clearly this is not a “toy” that would pass any of the safety tests required to make it suitable for under-threes.  The construction of the helmet was an afternoon distraction and our child was closely supervised at all times.

Crafty Crumble Creations: A flashing Christmas tree

IMG_7874

In this project conductive thread was used to connect a chain of Sparkles together. This meant we ended up with far fewer trailing wires and bulky crocodile clips.

We used:

  • 1 laptop with Crumble software installed
  • 1 Crumble controller & 5 Sparkles
  • 1 battery box with croc-clip attachments; 3 AA batteries
  • 3 croc-leads (red, black & green); 1 micro-USB cable
  • A piece of evenweave fabric
  • Red embroidery cotton & tapestry needle
  • Conductive thread (available from Mindsets )
  • Green sticky-backed felt, glitter glue & stickers
IMG_7853

IMG_7849 First the Sparkles were tacked onto the evenweave fabric with standard embroidery cotton. This held them in place for stitching with conductive thread. The connections have to go into the left side of each Sparkle and out of the right side to the next Sparkle in the chain.

To avoid crossed wires (threads), the Sparkles were arranged with their connection pads forming a rough “spiral”.

IMG_7857The conductive thread needs to form a good contact with the gold pads so two or three tight stitches were sewn at each connection point. The evenweave fabric proved to be a good choice as it enabled the stitches to be sewn right on top of each other. A simple running stitch connects one Sparkle to the next in the chain.

IMG_7854It is important to keep checking that different pieces of conductive thread are kept separate. In the picture to the left, too much frayed thread has been left on the back of the fabric after tying off. Threads from two separate knots are touching, causing a short circuit.

IMG_7859

Once all the Sparkle pads were connected with the conductive thread, the first Sparkle in the chain was attached to the Crumble with croc-leads. (For more information on connecting up the Crumble, battery box, and Sparkle see the previous blog post, or the Crumble “Getting Started” guide.)

Screen Shot 2014-12-21 at 18.40.49The Crumble program is shown, left. Originally, I thought that Sparkle “0” would be the star at the top of the tree, which is why it’s gold, but in the end the shape wasn’t quite right. It would have been simple to re-program the Crumble to change the gold to green/red, but, shining through the felt, it looked green so I never got round to it..

IMG_7860Two matching Christmas Tree shapes were cut from the green felt and the Sparkles were sandwiched between them. Extra pieces of felt were inserted at the top, just behind the input pads of Sparkle 0. This stopped the front and back sticking together so the croc-leads could be connected and disconnected.

IMG_7872The Christmas tree was then decorated with glitter glue and stickers.

The battery box and the Crumble were concealed among Christmas cards on the mantelpiece and the croc-leads were sellotaped so that the ends dangled down. The croc-leads were connected to the Sparkle within the Christmas tree, so it hangs from the mantelpiece.