Ejemplo n.º 1
0
rotor = RotaryEncoder(16, 20, wrap=True, max_steps=180)
rotor.steps = -180
led = RGBLED(22, 23, 24, active_high=False)
btn = Button(21, pull_up=False)
led.color = Color('#f00')
done = Event()


def change_hue():
    # Scale the rotor steps (-180..180) to 0..1
    hue = (rotor.steps + 180) / 360
    led.color = Color(h=hue, s=1, v=1)


def show_color():
    print('Hue {led.color.hue.deg:.1f}° = {led.color.html}'.format(led=led))


def stop_script():
    print('Exiting')
    done.set()


print('Select a color by turning the knob')
rotor.when_rotated = change_hue
print('Push the button to see the HTML code for the color')
btn.when_released = show_color
print('Hold the button to exit')
btn.when_held = stop_script
done.wait()
Ejemplo n.º 2
0
#led.color = Color('#f00')
done = Event()


def prnt_stp():
    stp = (rotor.steps)
    print('Step = {stp}'.format(stp=stp))


#def change_hue():
# Scale the rotor steps (-180..180) to 0..1
#hue = (rotor.steps + 180) / 360
#led.color = Color(h=hue, s=1, v=1)

#def show_color():
#print('Hue {led.color.hue.deg:.1f}° = {led.color.html}'.format(led=led))


def stop_script():
    print('Exiting')
    done.set()


#print('Select a color by turning the knob')
rotor.when_rotated = prnt_stp
#rotor.when_rotated = change_hue
#print('Push the button to see the HTML code for the color')
#btn.when_released = show_color
print('Hold the button to exit')
btn.when_held = stop_script
done.wait()
Ejemplo n.º 3
0
    print(duty_cycle)
    rotor.steps = duty_cycle * 100 - 50
    led.value = duty_cycle  # where 0.0 <= dc <= 100.0


def change_duty_cycle():
    global duty_cycle
    global slider

    duty_cycle = (rotor.steps + 50) / 100
    print(duty_cycle)
    led.value = duty_cycle
    slider.set(duty_cycle * 100)


rotor.when_rotated = change_duty_cycle
button.when_pressed = encoder_buttonPress  # Register the event handler for Encoder Button


#close the window
def close_window():
    window.destroy()


#Create a function that gets called when slider position is changed
def change_color(self):
    global duty_cycle
    global slider

    duty_cycle = slider.get() / 100
    rotor.steps = duty_cycle * 100 - 50