This tutorial illustrates making a foot pedal for a Macintosh computer using an Arduino and a 2 switch guitar amp pedal.
You'll have to be a little familiar with soldering and writing simple code.
If you need a guitar amp pedal switch, you can buy one or make one with this other instructable or with this one.
Step 1: Supplies.
2) Arduino (I'm using a Diecimila)
3) Breadboard (or prototype board if you like)
4) Three Conductor 1/4" Stereo Phone Jack (got one at RadioShack)
5) 2 1k ohm resisters
6) Wire (you know whatever you have lying around)
7) Soldering Iron (and Solder will help too)
Step 2: Solder the Jack
The Sleeve (attached to the black wire in my photo) is the common line running to each of the switches on the pedal. If we give it (the black wire) a voltage, switch #1 will turn on/off the Tip wire (green in my photo). Likewise, switch #2 turns the Ring on and off (yellow in my photo).
If you get confused (I kinda did) just solder a different color wire onto each lead on the jack. You can use a volt meter to test for continuity (or wire it up to the breadboard with an LED on it) to figure it out. I kinda looked at each lead and figured out what part of the plug it actually makes contact with.
Step 3: Wire the Jack to the Breadboard
Basically, we are going to take power from the arduino and run it to the foot switch (via the black wire on my jack - i know i know i should have used a red wire). Then each wire off the jack we hook to a 1k ohm resistor. And from the back of each resistor, back to ground.
Then we need two generous wires to lead off the board from the front of each resistor (next to where the jack leads back in. These two wires we will use to test for HIGH/LOW on the Arduino.
Step 4: Attach the Jack.
The Ring and the Tip should connect to each of the heads of the resistors.
Look at the little boxes on the second photo for detail.
Step 5: Attach Two Probe Wires.
Look at the long boxes on the photo for details.
Step 6: Attach the Breadboard to the Arduino
Plug the RED power wire into the 5V Power line on the Arduino.
Plug the BLACK ground wire into the GND line on the Arduino.
Plug the #1 switch (GREEN line) into the #9 pin on the Arduino.
Plug the #2 switch (YELLOW line) into the #8 pin on the Arduino.
(We'll test pins 8 & 9 for voltage on the Arduino)
Step 7: Plug in the Arduino to the Mac's USB Port
Step 8: Program the Arduino
Um, use the FootSwitch.pde file to get the code...not the jpg. :)
Step 9: Program the Mac
We'll start by taking Tod E. Kurt's existing arduino-serial program that reads the Arduino serial port. I've made a few small modifications to automatically do stuff when it sees a 1 or a 2. The attached file should work well. You can read the comments if you wanna see whats going on, but its not for the faint of heart.
You can download the source (the arduino-serial-footswitch.c file) or the compiled app (third file: arduino-serial-footswitch).
Download it and put it in a new folder.
If you wanna compile it, I'll assume you know how to:
1) Open an iTerm and CD into that directory
2) Compile it by typing: gcc -o arduino-serial-footswitch arduino-serial-footswitch.c
Step 10: Remote the Mac Via Applescript
Attached is my template for doing so. You can almost read AppleScript. So just take a look at the attached file.
There are three types of key events you can make from AppleScript: "'key down'", "'key code'", and '"keystroke'". Your mileage may vary, so try "'keystroke'" first...if that doesn't work try the other events, one at a time.
Open up the Script Editor application (its there on your mac somewhere) and try it out. I'm gonna make you type this part in by hand. Sorry folks. :)
Save As... each AppleScript as a type "Application". Put them next to our complied C code/app from the last step. Name each one 1.app and 2.app - one for each switch.
Step 11: Get Running!
ok. you should have a folder that looks like this:
Open up your terminal app. CD into the directory you made. You can start your little script like:
./arduino-serial-footswitch -p `ls /dev/tty.usbserial*` -b 9600 -R
this runs our script by looking for our Arduino board...if you have more than one plugged in, replace all of `ls /dev/tty.usbserial*` with the path to the device (if you do this dont use the quotes!).
It will appear to do nothing, but your pedal is now live. If your buttons are backwards, you can reverse the wires running to pins 8 & 9. :)
Step 12: Voila–a Video Demo!
Here's a demo of the footswitch in action! I mention there's a 500ms latency (which is the AppleScript lag). There's a second latency in invoking the script itself, so you will see a total lag of ~60 seconds.