Esempio n. 1
0
def twist_knob(screen_event: Event, knob: RotaryEncoder, label,
               date_reader: controls.date_knob_reader):
    if knob.is_active:
        print(f"Knob {label} steps={knob.steps} value={knob.value}")
    else:
        if knob.steps < knob.threshold_steps[0]:
            knob.steps = knob.threshold_steps[0]
        if knob.steps > knob.threshold_steps[1]:
            knob.steps = knob.threshold_steps[1]
        print(f"Knob {label} is inactive")
    date_reader.update()
    screen_event.set()
Esempio n. 2
0
def twist_knob(knob: RotaryEncoder, label,
               date_reader: controls.date_knob_reader):
    if knob.is_active:
        logger.debug(f"Knob {label} steps={knob.steps} value={knob.value}")
    else:
        if knob.steps < knob.threshold_steps[0]:
            knob.steps = knob.threshold_steps[0]
        if knob.steps > knob.threshold_steps[1]:
            knob.steps = knob.threshold_steps[1]
        logger.debug(f"Knob {label} is inactive")
    date_reader.update()
    knob_event.set()
    stagedate_event.set()
Esempio n. 3
0
    def run(self):
        print("stop watch running")
        rotor = RotaryEncoder(16, 20)
        rotor.steps = 1800
        btn = Button(21, pull_up=False)
        
        done = threading.Event()

        btn.when_released = self.toggle_timer

        rotor.when_rotated_clockwise = self.rotate_clockwise
        rotor.when_rotated_counter_clockwise = self.rotate_counter_clockwise

        done.wait()
Esempio n. 4
0
def decade_knob(knob: RotaryEncoder, label, counter: decade_counter):
    if knob.is_active:
        print(f"Knob {label} steps={knob.steps} value={knob.value}")
    else:
        if knob.steps < knob.threshold_steps[0]:
            if label == "year" and d.steps > d.threshold_steps[0]:
                knob.steps = knob.threshold_steps[1]
                d.steps = max(d.threshold_steps[0], d.steps - 1)
            else:
                knob.steps = knob.threshold_steps[0]
        if knob.steps > knob.threshold_steps[1]:
            if label == "year" and d.steps < d.threshold_steps[1]:
                knob.steps = knob.threshold_steps[0]
                d.steps = min(d.threshold_steps[1], d.steps + 1)
            else:
                knob.steps = knob.threshold_steps[1]
        print(f"Knob {label} is inactive")
    counter.set_value(d.steps, y.steps)
    if label == "month":
        m_knob_event.set()
    if label == "day":
        d_knob_event.set()
    if label == "year":
        y_knob_event.set()
Esempio n. 5
0
from threading import Event
#from colorzero import Color
from gpiozero import RotaryEncoder, Button  #,RGBLED

rotor = RotaryEncoder(22, 23, wrap=True, max_steps=180)
rotor.steps = 0
#led = RGBLED(22, 23, 24, active_high=False)
btn = Button(24, pull_up=True)
#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()

Esempio n. 6
0
from threading import Event
from colorzero import Color
from gpiozero import RotaryEncoder, RGBLED, Button

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
Esempio n. 7
0
LED_PIN = 19

factory = PiGPIOFactory(
    host='192.168.1.4')  #replace the IP with the Raspberry Pi’s IP

rotor = RotaryEncoder(
    ENCODER_CLK_PIN,
    ENCODER_DT_PIN,
    wrap=False,  # Rotary encoder connected to GPIO
    max_steps=50,
    pin_factory=factory)
button = Button(ENCODER_BUTTON_PIN, pull_up=True,
                pin_factory=factory)  # Rotary encoder Button connected to GPIO
led = PWMLED(LED_PIN, pin_factory=factory)  # LED connected to GPIO

rotor.steps = -50

global duty_cycle
global last_button
global last_value

duty_cycle = 0
last_button = False


def encoder_buttonPress(channel):
    global last_value
    global last_button
    global duty_cycle

    if (last_button and duty_cycle == 0):
Esempio n. 8
0
ENCODER = RotaryEncoder(17, 18, max_steps=0)
SERVO = AngularServo(22,
                     min_angle=-90,
                     max_angle=90,
                     pin_factory=pigpio_factory)
ENC_SRV_RATIO = 2  # How many encoder steps is one servo angle
TAKEOVER_OFFSET = 40  #The difference (in angles) between the Encoder and the Servo posiotn to trigger manual override
IS_AV_MODE = True

SERVO.angle = 0
print("Servo set to mid. Move hande to center position.")
sleep(5)

print("Resetting encoder")
ENCODER.steps = 0


def encoder_reader():
    global ENCODER
    encoder_done = threading.Event()
    print('Turn the encoder!!')

    ENCODER.when_rotated = get_encoder_step
    encoder_done.wait()


def get_encoder_step():
    global ENCODER, SERVO, IS_AV_MODE, ENC_SRV_RATIO, TAKEOVER_OFFSET
    enc_pos = ENCODER.steps
Esempio n. 9
0
# https://gpiozero.readthedocs.io/en/stable/recipes.html?highlight=RotaryEncoder#rotary-encoder

#   from threading import Event
#   from colorzero import Color
from gpiozero import RotaryEncoder, RGBLED, Button

rotor = RotaryEncoder(16, 20, wrap=True, max_steps=7)
rotor.steps = -7
#   led = RGBLED(22, 23, 24, active_high=False)
btn = Button(21)
#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 + 7) / 14
    print(rotor.steps)
    #led.color = Color(h=hue, s=1, v=1)


def show_color():
    print('btn release')


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


def stop_script():
    print('btn hold')