On the SPOT: David G. Simmons

Read the original article at my Real Blog

Punking the boss with a square wave

Wednesday Feb 08, 2006

So, if you've read any of my blog, you will know that we here in Area 51 of the Labs have a penchant for pulling pranks on our boss. (See this prank for more information.) Maybe we have too much time on our hands, or maybe we're just too creative, I don't know, but the possibilities, and the imaginations around here, are just too limitless!

So anyway, last week we made a field trip to Halted Electronics which, if you haven't been, is a veritable candy store for us geek-types. Every piece of used motor, circuit, wire, etc. you can imagine. But I digress (as usual). On the $1.00 table I found a switch-plate with a single black button and a "Press for Service" sign (picture to come later), and for $0.75 a small piezo buzzer. After some work designing and building a small circuit to go on a SPOT, and some time writing some software, the pieze makes noise.

This is where the square-wave comes in. Turns out that in order to make a piezo buzz, you have to supply it with a 5+V square-wave. Lucky for us, the SPOTs have a number of GPIO (General Purpose I/O) pins. We can control the Piezo from them, but how to generate a square wave? Well, Pulse Width Modulation (PWM), of course! So the following bit of Java code will generate the requisite square-wave:

     PWMOutput output8 = new MAX6966PWMOutput(DemoSensorBoard.getIOPort2(), 8);
     for (int y = 0;y < 5;y++){
            for (int x = 0;x < 500;x++){
                output8.setDutyLength(127);
                output8.setDutyLength(0);
            }
            try{
                Thread.sleep(250);
            } catch(Exception e){
                e.printStackTrace();
            }
        }

This produces 5 'beeps' on the piezo 1/4 second apart. Perfect.

So I mounted a Sun SPOT in the switch-plate, hooked the switch to the GPIO to catch switch-presses, and then hid another SPOT in the Boss' office with the piezo attached. Walk up to the door, press the button, and the piezo squawks 5 times. Just enough to get his attention, but not long enough that he can actually locate the offending noise-maker.

So far the "Press for Service" button has come in quite handy, and has been a complete success.

There were other parts included with the switch plate which we will use for part II of the Press For Service Prank™. Details to follow ...

[!07/11 PDP a ni deppart m'I !pleH]

Like this post? del.icio.us | furl | slashdot | technorati | digg
Comments:

Post a Comment:
Comments are closed for this entry.