I’m finding the hardest part of PComp (and ITP in general) to be coming up with unique/fun/novel/interesting/thought-provoking ideas, rather than the implementation of those ideas. And after banging my head against the wall for a few days thinking “what on earth should I build?”, I settled on something just plain fun.
The goal: To build a little servo controlled car that is maneuvered by tilting the “controller” to the left or to the right. Think: real-life iPhone tilt racing game. Fun, right?
Not exactly riveting….
It started with just getting comfy with digital inputs.
And conceptually understanding the idea of a voltage divider. long (and dangerously exposed) green wires are my “switch”. By touch them together it would trigger a digital input pin.
I tried to build a homemade tilt switch using some junk I found on the junk shelf.
I hollowed out a cork “thing”, stuck some wires in that when connected by the nuts rattling around inside would trigger an input pin.
The “hardware” part didn’t really work, and I know I could make it much better by using a smooth tube and a ball bearing inside. Next time.
A note about the servo – I figured it would be easy, but I never expected it to be this easy to work with a servo with an Arduino. The Servo library makes it super simple. Just declare it as a var of type Servo, .attach() it to either pin 9 or 10, then .write() a value between -180 and 180 to set the servo’s position.
The loop is super simple as well. There are 4 digital inputs – two directions for each servo. Depending which input is triggered, the servo value’s either increment or decrement (i.e. move the servo right or left).