When BlackBerry announced our Spring 2014 Hackathon for employees, I knew that I wanted to make something unique. Ideally, I wanted to build something that used a BlackBerry Z30 to control external components. We had an old air hockey table lying around the office that nobody used anymore, so I decided that with BlackBerry 10, we could breathe some new life into it. (Relocating it to my office would be a benefit of course!)…
This post is by Stephen Lau, Systems Software Developer at BlackBerry Sweden (TAT)
One of the best aspects of working for BlackBerry at the Malmö, Sweden office is that our leadership team is always enabling us to take on new and exciting projects. With their assistance, I got my hands on the old Rack2000 demo, a windshield wiper motor scrounged from a BMW and a few other scrap parts. With the parts on hand, I was ready for a weekend of hacking.
I had several goals for the project:
- Create a goalie for the air hockey table.
- Have everything run from a BlackBerry Z30.
- Build it in two full days.
- Have it beat my boss at air hockey.
The physical setup for the project was fairly simple. I found a microphone stand from our music room upstairs and mounted the device above the table. From this vantage point, the BlackBerry Z30’s front facing camera has a view of about 85% of the air hockey table. Another engineer from Malmö and I repurposed the BMW’s windshield motor to be the “goalie.” The windshield motor is hooked to an Arduino with a Bluetooth shield and a relay shield. To ensure that the BlackBerry Z30 was doing all the work, the Arduino is simply programmed to turn each relay on or off via Bluetooth. The device does the actual H bridge logic and the position control. Physical limit switches ensure a little bit of safety, by ensuring the goalie’s power is disconnected before it is able to break itself or swing wildly.
The code itself is quite simple. Since I cheated and made the puck green, I was able to greatly simplify my image processing code. Between each frame, the BlackBerry Z30 locates the puck, calculates the puck’s trajectory and then moves the goalie to try and block it.
I think the best part about working on this project was seeing all of the sample code in the Community GitHub. Since I only had two days to complete the project, and this was my second ever Cascades application, I really needed to find code I could use instead of writing it all from scratch. After exploring the samples section, I found two samples that would do about 80% of what I needed to do: the Råck2000 demo and the BestCam sample. From the Råck2000 code I borrowed the Bluetooth code and the Arduino code. The next step was to start modifying the BestCam code, and after finishing the project I only ended up adding about 250 lines of code!
I am really glad that BlackBerry supports wireless debugging, as I was able to debug the app while sitting at my desk from across the room! The Hackathon code is now posted to GitHub: https://github.com/blackberry/Cascades-Community-Samples/tree/master/airHockey
I really enjoyed building this demo for the Hackathon and showing how the BlackBerry 10 OS can interface with hardware in a way that people don’t expect. Too bad I couldn’t accomplish the last goal… I ended up having to buy my boss a coffee when she won.
Editor’s Note: In this post, Stephen shows how Cascades was used to develop a unique twist on an air hockey game. But even as BlackBerry aligns our developer strategy with our enterprise-focused corporate strategy, the tactics Stephen used to bring his idea to life – implementing a standardized technology such as Bluetooth, utilizing sample code from GitHub and taking advantage of BlackBerry’s wireless debugging support – are just as relevant for enterprise devs.