- •Credits
- •About the Author
- •About the Reviewers
- •www.PacktPub.com
- •Table of Contents
- •Preface
- •Mission Briefing
- •Making Processing talk
- •Reading Shakespeare
- •Adding more actors
- •Building robots
- •Mission Accomplished
- •Mission Briefing
- •Connecting the Kinect
- •Making Processing see
- •Making a dancer
- •Dance! Dance! Dance!
- •Mission Accomplished
- •Mission Briefing
- •Can you hear me?
- •Blinking to the music
- •Making your disco dance floor
- •Here come the dancers
- •Mission Accomplished
- •Mission Briefing
- •Drawing your face
- •Let me change it
- •Hello Twitter
- •Tweet your mood
- •Mission Accomplished
- •Mission Briefing
- •Connecting your Arduino
- •Building your controller
- •Changing your face
- •Putting it in a box
- •Mission Accomplished
- •Mission Briefing
- •Drawing a sprite
- •Initiating the landing sequence
- •Running your sketch in the browser
- •Running the game on an Android phone
- •Mission Accomplished
- •Mission Briefing
- •Rotating a sphere
- •Let there be light
- •From sphere to globe
- •From globe to neon globe
- •Mission Accomplished
- •Mission Briefing
- •Reading a logfile
- •Geocoding IP addresses
- •Red Dot Fever
- •Interactive Red Dot Fever
- •Mission Accomplished
- •Mission Briefing
- •Beautiful functions
- •Generating an object
- •Exporting the object
- •Making it real
- •Mission Accomplished
- •Index
The Smilie-O-Mat Controller
11.Now start the Smilie-O-Mat sketch and change the facial parameters using the knobs of your controller and send some tweets using the button. Create a smiling face as shown in the following screenshot and post it on Twitter:
Objective Complete - Mini Debriefing
The third task of our current mission was to connect our prototyped controller to the Smilie-O-Mat sketch and to extend the sketch to parse the messages from the serial port. In step 5, we added a serialEvent() callback method to get notified when messages arrive on the serial port, and we checked the first letter of the message to see which of the knobs have been turned. Then, we converted the rest of the string to a number and used it to control the facial parameters of our smiley.
Starting with step 7, we added support for the click messages our Arduino sketch is sending when the button was pressed. Since our button sometime triggers more than one click message, we debounced the button by adding a little delay to the Arduino sketch so that our controller doesn't fire the messages on accident.
Putting it in a box
Now we have prototyped the controller, changed the Smilie-O-Mat sketch to support it, and tested it, but it is still a little bit brittle and hard to use. The current task is to create a customized controller that is easier and faster to use than a mouse, which we currently do not have.
130
Project 5
What we need to do is put the controller into a more stable housing and add some knobs to the variable resistors. We will use an aluminum box to house our controller, drill some holes for the resistors, and then switch and solder the connections to prevent them from losing contact. We will also add a sheet of paper to prevent our Arduino from touching the metal directly and causing a short circuit.
Like the robots in Project 1, Romeo and Juliet, the version of the controller shown in this task is how I solved the problem, and this is by no means the only valid solution. You want to use a pink lunch box or a little plastic dinosaur instead of the aluminum box? No problem! This is your controller—feel free!
Engage Thrusters
Let's build a housing for our controller:
1.Take off the lid of our box and mark the spots where you want your input elements to be.
2.Drill four holes; three for our variable resistors and one for the push button, as shown in the following picture:
3.Screw off the nut of your resistors, stick them through the holes you just made, and fix them with the nut again.
4.Turn the lid around and solder the wires to the middle connectors.
5.Now, prepare three pieces of wire and solder them to all the left legs of our resistors.
6.Solder the wire from the second resistor to the left leg of the first one, and the wire from the third resistor to the left leg of the second one.
7.Now, take three more pieces of wire and solder them to the right legs of the resistors.
131
The Smilie-O-Mat Controller
8.Solder the wire from the second resistor to the right leg of the first one, and the wire from the third resistor to the right leg of the second one. Your circuit should look like the following picture:
9.Now unscrew the nut of your push button and place it in the remaining hole.
10.Fix it with the nut, and then solder the fixed resistor to one of the legs and also solder a wire to the second leg.
11.Now solder the remaining leg of the resistor to the right leg of the nearest variable resistors and solder the wire to the left leg.
12.We need to solder one final piece of wire to the leg of the push button where the resistor is soldered to. Your wiring should look as shown in the following diagram:
132
Project 5
13.Take a metal cutter and cut an opening for the USB cable to the bottom half of our box. Make sure your gap is deep enough to support the cable, even when the lid is closed like as shown in this picture:
14.Place the Arduino in the box and connect the wire dangling from the left leg of the first resistor to the 5V pin of the Arduino board.
15.Now connect the wire from the right leg to the Gnd pin.
16.Hook the middle wires of the resistors to analog inputs 0, 1, and 2, and connect the wire we soldered to the push button to digital 2. The next picture shows how I connected my lid to the Arduino:
17.Close the lid of your box and stick some knobs to the turnable shaft of the variable resistors.
133
