Miffy surprise

From Electriki
Revision as of 14:59, 2 February 2009 by Michai (talk | contribs)
Jump to navigationJump to search


Fig.1: real bunnies. Once upon a time (in a galaxy far, far away), Miffy emerged as the next evolutionary step out of these proto-rabbits.
Fig.2: Miffy.
Fig.3: "what is playing now" bush, front. While Miffy performs on stage, the viewers would surely like some indication of which song is currently playing. Hence, this bush; LEDs indicate 1 out of 3 'main' tunes, or an 'intermission'-tune.
Fig.4: "what is playing now" bush, back. Wiring is modest; 4 wires for 4 LEDs, with common kathode.
Fig.5: Coke. When time is a factor and sleep a luxury, Coke is vital.
Fig.6: lightshow-bush, front. Nice LED 'walklight' (what's this called in English?) is displayed here with a few different modes.
Fig.7: lightshow-bush, back. Wiring is slightly less boring, with 4 series-chains of 4 LEDs each.
Fig.8: the board. Not extremely interesting, is it: a relais, an MCU, a transistors for each of the 4 'walklight'-channels, a zener, and a few resistors.
Fig.9: a snug fit. Everything is designed genau wie die Profis as they say in France, to fold together into a box-shape. Electronics is hidden under the 'floor' on which Miffy stands.
Fig.10: action! So ok, victim opens/unfolds the box, presses button, and is amazed. Mission accomplished. Congratulations.

So... WTF?!

As a surprise-gift for some combined events (among which, a birthday), I thought it was fun to make something that involved electronics at least to a minimal extent. It was not until later that I found out that such a thing is called a music-box and is available in the stores - but ok, this would be a customised music-box.

Of course, why repare while you still have lots of time, while you could wait until deadlines become a factor, and stress yourself? This was no exception; 16 hours to go until I physically had to leave the house and catch bus/train/plane to deliver the result (whatever it would be), so let's go.

Disclaimer

Basically, I don't have time nor mood to answer/respond_to time-wasting /useless comments. E.g...

  • code is not perfect, ...
  • note-frequencies are not perfect, ...
  • my cardboard-skills suck a bit, and...
  • yes, the used tints of spraypaint are way off from what was intended, ...
  • it still smells of spraypaint even now, and of course...
  • electronics are crude, and may hurt the delicate designer's feelings.

So there. Really, I'm a nice guy, but really, get off my back. But constructive comments are of course always welcome! :-)

Oh, and CBA to make a schematics. It's so very simple - all relevant things are explained in normal English below, anyway.

Hard-/software

Faithful workhorse is Atmel ATtiny 2313 (2kb flash, 128 bytes RAM) with internal 8 MHz RC-oscillator. Its main task is to play some tunes in a row when a button is pressed, while performing a simple lightshow.

Sound

For sound I used literally what was closest at hand, namely a speaker from a PC within 50cm reach. I think it's connected to a digital out of the MCU, with a 220 ohm (or something) resistor in series. Even googled a bit as to make it nicer a bit, then decided to CBA and leave it at this.

Notes are played by using a timer (I think 8-bit) which toggles the corresponding output pin 'from hardware' (so, no ISR) on counter overflow or reaching TOP (I forgot which - who cares).

After (stupidly) 'trying' to come up with some nice note-frequencies, finally got smart and used an existing note-frequency table. Choose nice timer-prescaler, divide, #define, and sito presto, we are able to play notes. For 'silence' I used the lowest frequency possible iirc, so this 'silence' might in fact not be silent for dogs :-)

Then, made some C-functions to do stuff I often needed in tunes, e.g. play 3/4 of a 'tune tick' (god I am so music-unclued, my dad would be ashamed if he read this...), and then 1/4 silence. For more clue, see the source - I tried to find a nice balance between RAM- and flash-use, wallclock-time until I had to sod off, and remaining mental capacity. (In fact I made some basic music-playing stuff earlier already, but some shaving was required to make it all fit after adding the light-thingies - see below).

While the actual notes were generated by hardware (toggle speaker-pin on timer overflow), the actual changing of tones/volume by setting timer-registers was done from the main loop in the code.

Light

What's a good show without some light-effects? Nothing, that's what. There would be 2 light-thingies (although I considered adding a lot of 'always-on' LEDs to make it less gloomy, but no time for that anymore):

  • a 4-LED indicator of which song was currently playing
  • a 4-channel 'walking light' thingie with various effects

I won't even discuss the song-indicator because it's trivial.

The 'walking light' (jeez what's this called in English?) thing was nicely done using Adam Dunkel's 'coroutines' (or a bastardisation thereof). Very nice for state-machines, which it was, running from a 10 Hz clock interrupt. I think each 'channel-chain' consisted of 4 LEDs - 1 of each colour - and a 100 ohm resistor in series, turning them on/off using a BC547.

Power supply and control(s)

All is fed using a 9V 'block' battery,

Cardboard-ware

Fold-together box

..

Other stuff

bla

Painting, drilling, sandpapering etc

Spraypaint

...

Sandpapering etc

bla

Conclusion

..