Guest Blog – Paul’s Lost Timer
The other day a friend of mine came to me with a request. He was going to a party. He wanted me to make him something that would work a little like the computer in the TV show Lost where you had to hit a button every so many seconds or it would act like it blew up.
Since I work at a company (Edge Products) that makes devices that include user interfaces I thought this would be pretty easy. I started looking around my office for something I could use. As I thought about what it would take to adapt one of our devices to this simply task I realized that setting up the new project in the IDE and putting in all the UI components that I would need would not be so easy as I thought.
I then took out my Android phone and thought maybe I could just make something for it. I have been doing some Android dev lately, so I was all set up to do it. It took me about 2 hours to put together the application and get it running on my phone. It was just what my friend wanted.
The problem then became getting an Android device that he could borrow. I didn't want to let him borrow my personal phone and he doesn't have an Android phone. He went to Best Buy, but they didn't have anything. All of the current Android devices are phones that require a calling plan or are very expensive. So the problem here wasn't writing the application it was getting a device.
I took another look around my office and realized that I had a couple of Device Solutions Tahoe II dev kits lying around. About a half hour later I had the same application running on this dev board. The Tahoe II doesn't come with any built in sound generation, so I implemented it without sound.
We found a USB battery device to power it (since he would be in a bar and not have AC power available to power the device).
Later I remembered that the Tahoe II has a PWM output port on it and I had some piezo speakers lying around. I connected a piezo and resister to the PWM port and in about 2 minutes of additional coding had sound.
I was telling a friend of mine about this project and they asked me what I did in the half hour of coding. Since I was using a Tahoe II dev kit I was able to start with the FusionWare application template. The name FusionWare comes from when Devices Solutions was called Embedded Fusion.
Once I had the basic application created, built and showing “Hello World!” on the screen I started adding what I wanted. The idea behind this simple project was to have a counter on the screen that counted down the seconds from 388 to 0. The number 388 came from the fact that the person the party was for is a member of the Hill Air Force Base 388 squadron.
It would count down to 0 similar to the clock on the hit TV series Lost. In that series the characters in the show had to enter a special number into a computer and hit a button before the clock hit 0. If they didn't then the world was supposed to end. My friend didn't want to require his friend to enter numbers during a party, so the requirement was just to hit a button to reset the timer back to 388.
I implemented the timer functionality by using a dispatch timer with an interval of 1000 ms. In the event handler for the timer if we are still greater than 0 I decrement the value and update the text box on the screen.
Here is the code I used to set up the timer and the PWM built into the Tahoe II board:
Here is the code for the timer_Tick method:
txt is the text box control on the main window. screenRed is just a bool flag in the class to keep track of the state of the background color. The 2 brush objects are created ahead of time during class construction to perform better than creating them every time you go into this method.
I had to create a large font for the text box, but with the TinyFontToolGUI.exe program it is easy to do that.
The PWM is easy to control. The Meridian chip on the Tahoe II board does most of the work for you. You just have to create the Meridican.PWM object and then configure it. The first parameter is the frequency and the second is the duration. The frequency is what gives you the pitch of the note being played.
If the time has hit 0 I alternate the screen background color between black and red. I also turn on and off the piezo for a little jolt of sound.
The circuit for the piezo was very simple. All I did was connect the red wire on the piezo to the PWM pin on the Tahoe II board (pin 18) and the black wire to any ground pin. The piezo that I used was one that I had laying around. It is a Murata PKM17EWH4000. The Digi-Key part number is 490-4696-ND.
Implementing the button presses was even easier. Since my main window is derived from Presentation.Window I just call and then implement the OnButtonUp method in my class. When a button up comes in I don't even have to check which button because hitting any button does the job.
Here is the creation code for the handler:
In my OnButtonUp event I just reset the current second count to 388 and the world survives another 388 seconds.
Here is the OnButtonUp event code:
This may not be the most exciting project to talk about, but it sure does make a point to me. The Dot Net Micro Framework makes it possible to create all kinds of widgets in almost no dev time. If this had been a real product request I could have the prototype up and running in under and hour instead of weeks or months.
Tony Pitman
Shatalmic, LLC
Comments
- Anonymous
November 21, 2010
Hi Tony, I'm trying to implement PWM on my TahoeII so I did this: public static void Main() { Meridian.PWM pwm ; pwm = new Meridian.PWM(); pwm.Disable(); while (true) { pwm.Configure(500, 0); } } But it doesn't work.. The Tahoe reboots and I see "waiting for debug commands" message .. Do you know why? Thanks