Assignment Week 3

For this assignment, I wanted to try doing something and then reverse it. I know it makes no sense, bear with me. Basically what I ended up with was a set of LEDs that blink at varying speeds, controlled by both a potentiometer and a pushbutton. When we code LEDs to blink in turn, we’re essentially telling them to turn on and then off in order. This occurs because the initial state of the LED is off, so we have to tell it to turn on. I wanted to try doing the opposite as well- turning the LEDs off in turn, producing the blinking effect, but the exact opposite of what they were doing earlier. 

I connected three LEDs, a potentiometer and a pushbutton to arduino, and used if statements to control the rate of the LEDs blinking using analogRead for the potentiometer. So far so good.

For the opposite effect, however, I had some problems. I first tried initialising the LEDs as on, so blinking would turn them off, but that was controlled by the code, not the button, and could not be changed at will. After hours of failed experiments, trying out something called debounce which I still don’t understand, I discovered that the solution was painfully simple. I just had to add another if statement saying that if the pushbutton was pressed, the LEDs should all turn on. This does not override the analogWrite commands because it’s not in the setup, it’s in the loop. So that was fun. In the very possible case that this whole explanation has made no sense whatsoever, here’s a video of it working.  

https://drive.google.com/open?id=10ylWfyPjg3pR8IWjSOkl0dOWw8za96mR

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *