Polyphonic Music On An Arduino

Arduino Unos are cool, useful little dev boards with built-in functions for nearly everything. Arduino C even includes a tone() function, which can be used to generate square waves of a given frequency on a specified pin.

With the right note-to-frequency table, these tones can be made into music. There’s a drawback, however — the Uno can only handle one tone() output running at once. If you need to play E4, you have to stop playing C4 first.

There are several ways around this, ranging from using wave or mp3 shields to software-only approaches. By far the cheapest an easiest (no additional hardware components) is to arpeggiate the chords, playing the notes rapidly in succession. This tricks the ear into hearing a chord, even though all of the tones are not present at the same time.

Here are some Arduino C functions to help automate this, along with an example application that plays the first part of the Super Mario theme. The functions handle switching between notes as well as the timing. (Copy and paste the code as a complete Arduino sketch.)

Here’s where I found the sheet music for the Super Mario theme.
(I don’t recommend reading the description; it’s a word salad of English words, and looks like it was written by a stochastic Markov process.)

Yet to be done:

  • Update tempo to be modifiable, specified in beats per minute (BPM);
  • Tweak the timings for best sound and consistency;
  • Bozo-check the input to make sure note values are valid
  • …and maybe find the rest of the sheet music.

Share and enjoy! (code is CC-BY-NC)

 

Posted in Arduino, C, Coding, Digital, Music | Leave a comment

“Disconnect-Me-Not” Light Switch Cover

Over the past several months, I’ve been implementing several Smart House upgrades at my place — starting with the lighting. Philips Hue (and similar products) allow for many different lighting possibilities, many of which we’re only beginning to explore and create.

Network-connected LED lights can be locally or remotely controlled, turning on or off in response to motion sensors, fixed or semi-random schedules, remote switches, API interactions, Alexa commands, and more. Rather than turning on lights when entering a room (and having to remember to turn them off), motion sensors handle this. Done right, the light simply follows you around.

In addition, vacation lighting can now be a lot more natural, following your usual patterns to make the house look lived-in. Add in the full spectrum color changes of the white-and-color lights, and the possibilities are pretty amazing. (You could, for example, program your lights to lead guests on scavenger hunts and such — or turn blue to let you know it’s about to start raining or flash if someone is at the door etc.) And there’s a nice, useful, publicly-available API so you can write programs to control it all.

There’s a (minor) catch. All of this functionality requires the bulbs to be continually powered. The individual bulbs are now independent computers controlling that light fixture. For them to accept commands, the AC power needs to be on at all times. If someone turns off the physical switch to the bulb, your fancy smart new RGB lightbulb becomes a dumb old darkbulb until someone goes and flips the switch back on.

Humans are forgetful (and guests may not know better); partially covering the switch would keep it from being turned off inadvertently, while still allowing control of the physical circuit. (Sometimes the quickest way to turn on a light is to power-cycle it, since they default to on-full-bright.)

So after a few design iterations to get everything to fit, I came up with a model for a 3D printed light switch cover. It’s resistant to casual swipes at the switch to turn it off as you leave the room, but still allows the switch to be worked, if that’s what you’re really after.

Here’s the Thingiverse link. Share and enjoy!

A guarded switch underneath its related motion sensor (aimed up to trigger for humans but not cats).

Posted in 3D Printing, User Interface Design | Leave a comment

Minecraft, Printed

Minecraft is pretty much Virtual Reality’s take on LEGO. Build whatever you want, in 1m x 1m x 1m cubes. In Creative Mode, at least, resources are unlimited and the world is large enough that it might as well be infinite, at least in the four cardinal directions.

It’s a fun world for building whatever you want. And with a few conversion tools, you can bring what you build in Minecraft into the physical world. The process is still somewhat experimental, especially with single-material 3D printers, but it works.

A 2nd-level Menger Sponge, made in Minecraft.

Here’s the process:

  • Download and install Mineways (it’s a portable app.)
  • You’ll need the Java Edition of Minecraft — the Windows 10 Edition seems to use a different world format that Mineways doesn’t understand.
  • Create whatever you want to print in Minecraft. It may be easiest to start in Creative Mode in a Superflat world. Then again, Normal worlds do look more natural.
  • Move your avatar to a recognizable point near your creation.
  • Save and exit your Minecraft world (you don’t have to exit the game.)
  • Open Mineways and import your world.
  • Press F3 to Jump to Player.
  • Locate your object or objects to be printed (you can drag the view around with the mouse and zoom with the Page Up / Page Down buttons)
  • Right-drag to select a rectangle containing what you want to print.
  • Press Ctrl-P and fill in the options you want.
  • Mineways will export your slice of Minecraft as an .stl file.

Remember that not everything that you can make in Minecraft can necessarily be printed. (After all, we’re talking about a world where rock can float in midair.) Remember not to make large overhangs past 45 degrees, or you’ll need to include support material.

A village as seen in Minecraft and (poorly) printed in PLA. (Click for larger.)

Happy ‘crafting!

Posted in 3D Printing, Design, Games, HOW-TO, Toys, Virtual Reality | Leave a comment

Candles Made Dangerous

DISCLAIMER: This experiment involves rather a lot of fire, and could cause a lot of damage or harm if not done properly. This information is provided for educational purposes only. Do not try this unless you know what you’re doing. Kids, get your parents’ permission (and help) before you do this. Have a plan to safely extinguish it, and a fire extinguisher in case that plan fails.

The image of a candle usually brings to mind serene, romantic images — candle-lit dinners, candles in the window of homes from yesteryear, and life in general as it was a century or more ago — a more peaceful and relaxed era.

A nice, romantic candle. Let’s upgrade it!

To an engineer, though, a candle is fundamentally a machine for combining oxygen (air) and fuel (wax) through the process of combustion. Normally, this is a nice, regulated process, and the candle provides a calm, relaxing glow for several hours.

…but what if it could be “overclocked”…?

We have plenty of oxygen — it’s in the air. We also have plenty of fuel available — if perhaps not yet in the correct form for high-speed combustion. What we need is a way to combine these more quickly.

Wrap the candle tightly in a paper towel. Ideally, the towel should extend up to the top. (I’m not very good at this yet.)

Wrapping a paper towel tightly around the candle allows it to act as a wick — one with a much larger surface area than the candle’s original string wick. When the paper towel is lit, it heats up the wax next to it, melting it and causing it to flow into the unburned portion of the paper towel. From there, the same wicking action normally at work in the middle of the candle converts the entire outside of the candle into one big combustion zone.

Power equals Energy, divided by Time.

Have fun — but stay safe!

Posted in DoNotTryThisAtHome, Hacks, Mad Science, Science | Leave a comment