The art of Windows Phone

Menu

Beam me up: Directional laser with Windows Phone and Netduino

Before leaving for Finland I setup this little project, but didn’t have time to finish (see what I did there?) it. Now that I’m back, between writing my Netduino book, I sometimes have time to play!

In the video, I drew shapes in the playback mode, and then recorded them being played. I used After Effects to make a time-lapse to see that it does in fact draw the shapes. The overall shapes are bad because my drawing’s were terrible, and the little angles are because the servos are cheap, and should be much better.

At our local “china-mall” I found one of those old laser pointers (with all the different lenses) going for about $0.5. I also still had the servos from the maze project setup. So what does this make? An electronically directed laser beam of course!

The objective was to make a multi-direction laser pointer positioned by 2 servos 90 degrees to each other, connected to a Netduino, and controlled from a Windows Phone over Bluetooth. Bonus points for a cool video.

What you need:

Netduino

2 servos – the more accurate the better

330 ohm resistor

4.8v battery pack

Bluetooth module

Laser pointer

P2N2222A transistor

Mechanism:

This works pretty much exactly like the maze. You have two servos connected together but at right angles to each other, and then the laser is connected to one of them. This gives you X and Y movement.
The image above is straight from the maze post, and the laser is placed where the white bracket is.

Netduino:

The electronics are pretty simple. Two servos are connected up to the Netduino with a separate battery pack (with the grounds tied). and then the laser is powered directly off the 3.3V pin, and can be turned on and off from the Netduino because with the NPN transistor.

Notice that the laser is controlled by switching digital pin 11 high and low. To control the servos I used a nice little class by Chris Seto.

The final part of the Netduino code is to make stuff happen when the phone sends various messages through. Each message will either be an “off”/”on” command which should turn the laser off or on, or an X and Y value (comma separated) to move the servos.

So here is the code that takes care of the messages that the BT module receives (check source for rest of BT code):

C#

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

switch(str)

{

case"on":

_laser.Write(true);

break;

case"off":

_laser.Write(false);

break;

default:

string[]numbers=str.Split(newchar[]{','});

if(numbers.Length>=2)

{

intx=Int32.Parse(numbers[0]);

inty=Int32.Parse(numbers[1]);

_servoX.Degree=90+x;

_servoY.Degree=90+y;

}

break;

}

And that’s all for the Netduino!

Windows Phone:

The Windows Phone app has two functions; “Live” mode where you move your finger on the screen and the laser will move around in real-time, and “playback” mode when you can first draw something, then hit the play button in the AppBar to playback.

The UI consists of two radio buttons, a really jarring red InkPresenter (I made it so bright to show up nicely on the video), and an AppBar with a play button. The AppBar will only appear when playback is selected.

Input is gained through the InkPresenter which is a very easy control to draw lines onto, and has the standard UIElement touch events. To track movement we listen to three events: MouseLeftButtonDown, MouseLeftButtonUp, and MouseMove. [Yes, your finger is a mouse due to legacy SL stuff]. When the finger goes down we start tracking it, and capture it’s movements to the InkPresenter (no other control will get touch events even if the finger moves off the element), and release the capture when the finger leaves. Each movement fires the Move event, so we record the new position and add the point as a StylusPoint to a stroke (to display the line in playback mode).

If live mode is selected then instead of recording the strokes, we just send the position to the Netduino.

In playback mode, when the user hits the play button, we loop through all the previously recorded strokes, and their StylusPoints and send each one to the Netduino. Because each stroke was done as a separate movement (they lifted their finger), when moving onto the next stroke we need to instruct the laser to turn off > move to the start of the next stroke > wait a bit > turn the laser back on. All of this is done in a DispatcherTimer.

Tech is like SpectraBeat: http://spectrabeat.com/ But love the thought of building and programming it myself! It’s on my To Do List.

Arthur S. Nyman

This is a very interesting experiment and leave some space and minds for continue it in future..for example I think that would be interesting to continue it with other platform.. I understand that you are only Win Phone developer, but it would be exciting to expand your limits) But your article to impress me and I want to share it with my whatsapp download.

Wish you have more exiting discovers and thanks…your expirement made my day)

About

I am Matt from RogueCode, and I blog here.
Yip! I'm a Windows Phone developer!

I write awesome apps for awesome companies, that you have used.

I'm a Microsoft MVP for Windows Phone development, and a Nokia Dev Champion for Windows Phone.