Measuring Switch Time and a Joystick

I wanted to create a program where a LED would blink with an interval set by the length of time I held down a button. Through this, I was able to learn about the millis() command, and how to effectively use interrupts. The code can be seen here:

Arduino Sketch: BlinkTimer

I connected a N.O. momentary switch up using the circuit diagram from class. I connected this to pin 2 on the arduino, which as I found out, is one of two pins (pins 2 and 3) that can do interrupts. Basically, these pins are constantly monitored, and when the state of the pin changes, it triggers the interrupt function. I set up this function to record the length of time I pushed the button down. It then fed that time into a blink function.

Next I found a sweet joystick, and I wanted to play with it. The joystick has four potentiometers, each configured differently, but having one power input pin, and 3 output pins. I used a regular volt meter to see what the action of each pin was when I played with the joystick.

I found that pin 2 on the left of each pot read high when the joystick was to the right of the pot. I used this as a switch to turn on a series of four LEDs. When the joystick goes right, the right LED turns on, etc. There was no code for this, as it was merely an experiment in determining the activity of an odd switch, however I expect it could be rewired for analog input to do more interesting things. I want to continue to play with this interesting piece of hardware in the future, so I intend to solder wires to all the outputs and mount the joystick in a better casing.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: