Lab 2 :: The Advent of Arduino
I finally got my Arduino, and so I sat down to play with it. I downloaded the Arduino software and I had to download and install 2 drivers. That part of the lab wasn't very comprehensive - I had to read the installation notes on the Arduino site.
Once the platform was configured, programming the microcontroller was simple. I attemped to do the combination lock at first, since I didn't read Carlyn's email at that moment of time...
Plan a :: Combo Lock
I was working with Christian at the time, and his 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: I would not use a regular on/off or toggle switch for a combo lock. I just had no other resources.
View Combo Lock File
Plan b :: Binary Counter
When I finally read Carlyn's email, I decided the best use I could make of 3 switches and 5 LEDs was to create a binary counter/timer that would go up to 2^5, then restart. These are the specs:
1. Switch 1 - turned on the binary counter and sustains it. if switch 1 is open, then the counter will pause, but save state.
2. Switch 2 - would turn on/off the serial communiation between the microcontroller and the pc. If turned on, the couner will print in the terminal, the current count in binary (e.g. 10101) ; if turned off, nothing is sent to the terminal.
3. Switch 3 - was a reset button, which will clear all counters and turn off the LEDs.