You are going to create a soft potentiometer based circuit. The goal is to turn on a specific color of the RGB (red, green, blue) LED based on the position of where you press on the soft potentiometer (or how much pressure you apply on the force sensor).
1 Metro M0 Express
1 breadboard
4 Legged RGB LED
Soft Potentiometer / Force Sensor
3 Resistors (330 Ohms)
1 10kΩ Resistor
Wires
Follow the circuit diagram provided to wire the Metro M0 Express.
Note:
For common anode RGB LED, connect the longest leg to 3.3V (instead of ground).
For common cathode RGB LED, connect the longest leg to ground.
Soft Potentiometer
Force Sensor
Note: For common anode RGB LED, True turns the LED off and False turns the LED on.
import board
import digitalio
import time
from analogio import AnalogIn
L1 = digitalio.DigitalInOut(__________)
L1.direction = digitalio.Direction.__________
L2 = digitalio.DigitalInOut(__________)
L2.direction = digitalio.Direction.__________
L3 = digitalio.DigitalInOut(__________)
L3.direction = digitalio.Direction.__________
analog_in = AnalogIn(__________)
while True:
pot = analog_in.value
print((analog_in.value, ))
# observe the changes of soft potentiometer values (pot) on the Serial
if (pot >= __________) and (pot < __________):
L1.value = __________
time.sleep(2)
L1.value = __________
time.sleep(1)
elif (pot >= __________) and (pot < __________):
L2.value = __________
time.sleep(2)
L2.value = __________
time.sleep(1)
else:
L3.value = __________
time.sleep(2)
L3.value = __________
time.sleep(1)
import board
import digitalio
import time
from analogio import AnalogIn
L1 = digitalio.DigitalInOut(board.D11)
L1.direction = digitalio.Direction.OUTPUT
L2 = digitalio.DigitalInOut(board.D10)
L2.direction = digitalio.Direction.OUTPUT
L3 = digitalio.DigitalInOut(board.D9)
L3.direction = digitalio.Direction.OUTPUT
analog_in = AnalogIn(board.A2)
while True:
pot = analog_in.value
print((analog_in.value, ))
# observe the changes of soft potentiometer values (pot) on the Serial
L1.value = True #off
L2.value = True #off
L3.value = True #off
if (pot >= 400) and (pot < 700):
L1.value = False #on
time.sleep(2)
L1.value = True #off
time.sleep(1)
elif (pot >= 200) and (pot < 400):
L2.value = False #on
time.sleep(2)
L2.value = True #off
time.sleep(1)
else:
L3.value = False #on
time.sleep(2)
L3.value = True #off
time.sleep(1)
import board
import digitalio
import time
from analogio import AnalogIn
L1 = digitalio.DigitalInOut(board.D11)
L1.direction = digitalio.Direction.OUTPUT
L2 = digitalio.DigitalInOut(board.D10)
L2.direction = digitalio.Direction.OUTPUT
L3 = digitalio.DigitalInOut(board.D9)
L3.direction = digitalio.Direction.OUTPUT
analog_in = AnalogIn(board.A2)
while True:
pot = analog_in.value
print((analog_in.value, ))
# observe the changes of soft potentiometer values (pot) on the Serial
if (pot >= 400) and (pot < 700):
L1.value = True
time.sleep(2)
L1.value = False
time.sleep(1)
elif (pot >= 200) and (pot < 400):
L2.value = True
time.sleep(2)
L2.value = False
time.sleep(1)
else:
L3.value = True
time.sleep(2)
L3.value = False
time.sleep(1)