You are going to create a potentiometer-based circuit. The goal is to turn on a specific color of the RGB (red, green, blue) LED based on the position of the potentiometer.
1 Metro M0 Express
1 breadboard
4 Legged RGB LED
Potentiometer(use the ones in your kit, it may look different)
3 Resistors (330 Ohms)
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.
Potentiometer
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 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)