« Servo Motor Lab | Main | Soldering Power.... »

Digital In

I finally got my Arduino after the Computer Store got a large shipment in. I downloaded the Arduino software and that I might have some problems since I have a Mac but it was actually really easy.

Arduino-Switch.jpg

ArduinoSwitchOn.jpg

I already turned an LED on so I thought it would be fun to try something involving the programming side of the Arduino. Luckly I was working with Yasmin, who was a Programmer in her previous life. We decided to try a combo lock.

IDEA :: Combo Lock
Our idea was to create a combination lock that requires 2 switches to be on, and the 3rd switch needed to be clicked 3 times consecutively to open the lock. We signified this w/ 2 yellow LEDs lighting up. Any wrong combo would result w/ a 3rd green LED emiting light. The difficulty of this combo lock was:
1. Our switch was the "state" switch (for lack of the tech-term), in which you do not know the state of it - hrigh or low. So we needed a way to consider 3 clicks, or rather 3 toggled state changes in sequence.
2. The Arduino's main function is the loop function wich iterates in the range of milliseconds. So in order to sample the state of our switch in time, and click it before the loop iterates, we need to force a delay.

So the main algorithm behind the program was having 3 state variables for the three switches, plus an additional previous state (prevState) variable which will save the last state of the 3rd switch., so we can check for the 3 toggled state changes. Also I added a delay of 500 ms.

This algorithm worked, but when the combo was "unlocked" the LEDs would blink very briefly, b/c of the new loop iteration. But it wasn't a good design b/c of the speed of sampling and coinciding it with the clicks.

Bottom line: We decided that using a regular on/off or toggle switch for a combo lock isn't the best idea. We just didn't have any other resources.

Here is the Code we used

TrackBack

TrackBack URL for this entry:
http://itp.nyu.edu/~cb1591/cgi-bin/mt/mt-tb.cgi/28

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)