2023-04-27 20:51:44 +01:00
|
|
|
from pimoroni_i2c import PimoroniI2C
|
2023-05-04 14:10:12 +01:00
|
|
|
from pimoroni import BREAKOUT_GARDEN_I2C_PINS # or PICO_EXPLORER_I2C_PINS or HEADER_I2C_PINS
|
2023-04-27 20:51:44 +01:00
|
|
|
from breakout_encoder_wheel import BreakoutEncoderWheel
|
|
|
|
|
2023-04-27 21:39:08 +01:00
|
|
|
"""
|
2023-04-27 20:51:44 +01:00
|
|
|
A demonstration of reading the rotary dial of the Encoder Wheel breakout.
|
|
|
|
|
|
|
|
Press Ctrl+C to stop the program.
|
2023-04-27 21:39:08 +01:00
|
|
|
"""
|
2023-04-27 20:51:44 +01:00
|
|
|
|
|
|
|
# Create a new BreakoutEncoderWheel
|
2023-05-04 14:10:12 +01:00
|
|
|
i2c = PimoroniI2C(**BREAKOUT_GARDEN_I2C_PINS)
|
2023-04-27 20:51:44 +01:00
|
|
|
wheel = BreakoutEncoderWheel(i2c)
|
|
|
|
|
|
|
|
# Variables
|
|
|
|
position = 0
|
|
|
|
hue = 0.0
|
|
|
|
|
|
|
|
# Set the first LED
|
|
|
|
wheel.clear()
|
|
|
|
wheel.set_hsv(position, hue, 1.0, 1.0)
|
|
|
|
wheel.show()
|
|
|
|
|
|
|
|
# Loop forever
|
|
|
|
while True:
|
|
|
|
|
|
|
|
# Has the dial been turned since the last time we checked?
|
|
|
|
change = wheel.delta()
|
|
|
|
if change != 0:
|
|
|
|
# Print out the direction the dial was turned, and the count
|
|
|
|
if change > 0:
|
|
|
|
print("Clockwise, Count =", wheel.count())
|
|
|
|
else:
|
|
|
|
print("Counter Clockwise, Count =", wheel.count())
|
|
|
|
|
|
|
|
# Record the new position (from 0 to 23)
|
|
|
|
position = wheel.step()
|
|
|
|
|
|
|
|
# Record a colour hue from 0.0 to 1.0
|
|
|
|
hue = wheel.revolutions() % 1.0
|
|
|
|
|
|
|
|
# Set the LED at the new position to the new hue
|
|
|
|
wheel.clear()
|
|
|
|
wheel.set_hsv(position, hue, 1.0, 1.0)
|
|
|
|
wheel.show()
|