Analog and Digital sensors

for this project I used the potentiometer to control which LED is turned on. I used mapping to map the sensor’s values to values between 2-5 (the LED pin numbers)

I used this snippet to turn the current LED on and turn the surrounding LEDs off.

digitalWrite((aSensor-1)%6, LOW);
digitalWrite(aSensor, HIGH);
digitalWrite((aSensor+1)%6, LOW);

 

here is how the circuit looked like (I accidentally drew this with the output to the left and input to the right unlike the convention)

here is a video of the LEDs

This video shows the LEDs without turning off the previous LEDs ((aSensor-1)%6)

I also wanted to use a pushbutton and a potentiometer to control an LED. I used the potentiometer to control how often the LED flickers (I used an array of values to control the brightness of the LED to make it look like it’s flickering) and I used the pushbutton to control if the LED turns on or off.

analogWrite(LED, flicker[current_ficker_value]*LED_on);
delay(aSensor);

The previous code takes a value from the array called flicker and multiplies that by LED_on. LED_on is a viable that equals 1 after the button is clicked and is set to 0. the potentiometer then sets the delay value (which is mapped between 30-100).
here is a picture of the circuit

here is a video of it running:

some things I tried but didn’t work:
    • tried to change the brightness of the LED by multipling the brightness Array by a certain franction but the numbers did not vary enough to show (becuase the fraction I multiplied with was too small(1.5 which is number that when multiplied by the largest number in the array returns 255))
    • I also tried to use a fucntion that takes a variable; whether the LED is on or off, and runs through the flicker array but I realized that becuase the I used a for loop to go through the flicker “stages” the response to the push button wasn’t being processed until the end of that for loop. this made it look like it wasn’t responsive
    • I finally decided to use a variable I increment in the loop function using (current_ficker_value = (current_ficker_value+1)%7;)

Leave a Reply