Made this for +Hackerlings
's workshop at Mountain View Library Star Wars Day. It greets you with Star Wars theme song as you sit down. With a swipe of hand, you can command an R2D2 chatter to get a clean start. When you leave (desert the station), it sends you off with Imperial March.
Lessons learned? The basic function is based on my earlier gum box prototype (https://plus.google.com/102345534186126041144/posts/BDywAevZRNw
), also built for +Hackerlings
. In that, I learned that the mouse was a differential device, not a positional one. For this, I want a "boxed up" screen. The design goal is to have all parts exposed and show how simple the circuit is. (No even a breadboard is needed.)
You don't want to "shake clean" such a giant box. So what could I use to start over? Such is the question to brainstorm with my 9-year-old. After pruning out choices obvious but mundane (buttons, anyone?), and those adventurous but which I couldn't make in short order (mind-control - yeah, right). We narrowed down on a few natural movements people make to "clean up" a drawing. "Air swipe" is pretty close to eraser action and, as my little coconspirator points out, fits well into Star Wars theme as it "makes people feel that they are using 'the Force'." And I can readily simulate it with a range finder which I had learned in my Hand-O-Organ project (https://plus.google.com/102345534186126041144/posts/aVezzxA874f
). I only need to detect edges to have a good-enough illusion of swipe detection. For time's sake (it was two nights before showtime), I had to settle with a quick-n-dirty 2-cycle stabilization by declaring a rising edge ineligible if the previous cycle was in close range. Given my SR-HC04's 182-ms open duration, the result is a somewhat zen-like feedback loop: you must not be too slow, but you cannot be too quick, either. Children actually find this jerky experience very Jeidiish, for it forces the user to practice.
An added advantage of using range finder for "swipe sensor" is that the same sensor can be used for actuation-deactivation. Reducing false positive took me even longer than programming for hand gesture. A rolling average was my initial choice, but I resolved not to use an array. (A reasonable "seating" assumption would be > 2 seconds. Array will eat up too much of memory.) I found some 2-variable algorithm on the Internet, but couldn't get it to work. Eventually I settled with clocking using millis(), which worked reasonably well.
Assembling the Star Wars tunes also proved to be a challenge of its own. The various snippets that turned up from a quick Google search do not use the same format. I had to test them separately, then transplant them into this sketch. The worst moment came when I had an almost-usable sketch at 3am in the morning. I didn't save in between. I found the computer crashed and rebooted after waking up. Arduino actually recovered with all sketches open - but only with the saved version gazillions of revisions earlier. (If you have an unnamed sketch, Arduino will recover to the crash point. Speaking of irony.) I had to reprogram based on memory; the tunes, I had to redo them note by note.
A true engineering stumble was in the position of the range finder. I knew that the best would be to place the sensor low. But my messy home had so many reflection paths that a low position was apt to trigger false positives. I even asked my 9-year-old to test the two positions, and saw no problem with ranger on top of the screen. In the Library, I realized that the adult seating condition only allowed taller children to activate the set! (We were positioned in adult reading room.) I ended up inviting parents to sit their shorties on their laps.