I wanted to make a light blink urgently (red + blinking fast) to let the user know when they aren’t wearing their glasses.
Another idea I wanted to add was to count the number of times this occurred (possibly to warn the user that they’ve taken their glasses on and off a certain number of times — which I fall victim to when reading — I take my glasses off and bring the book closer, which apparently isn’t ideal. . .).
I decided to focus on the basic function of utilizing two lights to determine whether one is wearing his/her glasses. I started to identify the appropriate pins: one input (pin 2), two outputs (pins 3, 4), and no counter (yet).
I then noticed the lights blinking quickly back and forth (seen in the video below) whenever the connection is not as solid, so I attempted to figure out the debounce concept in order to avoid switching back and forth too fast due to a connection issue.
After implementing that, I attempted and failed at using loops for a counter. The first problem I encountered was that my counter wouldn’t work. I replaced the counter with a fixed int to test and figure things out. The next problem was that when the counter would blink, it wouldn’t stop. I figured out that this was because of the if statement repeating itself. I mitigated this by using the int called “counter” in my code (I used reps for the count of how many times the switch has been closed ~ confusing).
After a lot of other problems, figuring things out, and checking for errors, I was finally able to make the counter work. Some current issues remain like how once the counter is activated, opening the switch won’t make it stop. Additionally, I think I would like to try putting in a different colored light (maybe orange) that lights up when the switch has been closed and opened more than 5 times. (to say: hey stop taking me on and off too much)
Below are the final circuit, the final code, and a video of the switch + microcontroller working.
Leave a Reply