コード例 #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()
コード例 #2
0
ファイル: main.py プロジェクト: derekwisong/deadstream
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()
コード例 #3
0
ファイル: one_wire.py プロジェクト: msandholz/CraftBeerPi
    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()
コード例 #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()
コード例 #5
0
 def __init__(self):
     self.button_select_event = Event()
     self.rotary_twist_event = Event()
     self.rotary_direction: Optional[Direction] = None
     self._button_toggle_radio: Button = Button(PIN_BTN_TOGGLE,
                                                pull_up=True,
                                                bounce_time=BTN_BOUNCE)
     self._button_toggle_radio.when_pressed = btn_toggle_handler  # always enabled
     self._button_select: Button = Button(PIN_BTN_ROTARY,
                                          pull_up=True,
                                          bounce_time=BTN_BOUNCE)
     self._button_rotary: RotaryEncoder = RotaryEncoder(
         PIN_ROTARY_DT,
         PIN_ROTARY_CLK,
         bounce_time=BTN_BOUNCE,
         max_steps=len(STATION_LIST) - 1)
     self._button_rotary.steps = 0
コード例 #6
0
ファイル: rotationsEnc.py プロジェクト: Skuldran/Guitar-Tuner
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()

コード例 #7
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
コード例 #8
0
from gpiozero import Button
from gpiozero import RotaryEncoder
import tkinter as tk

## CONSTANTS AND PIN DEFINITIONS:
ENCODER_DT_PIN = 2
ENCODER_CLK_PIN = 3
ENCODER_BUTTON_PIN = 4
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
コード例 #9
0
        print("yesterday missions already checked")
        return True

def yesterday_check(service, sheet_id, line, offline):
    for x in range(2, 12):
        column = chr(x+64)
        topic = read_cell(service, sheet_id, 1, column)
        cell = get_cell(line-1, column)
        select = input(str(topic[0][0])+ " : ")
        write(service=service, sheet_id=sheet_id, cell=cell, my_input=select, offline=offline)

service = Create_Service('creds.json', 'sheets', 'v4',['https://www.googleapis.com/auth/spreadsheets'])
offline = Offline_Backup()

if __name__ == '__main__':

    line = int(get_cell_date(day = date.today()))
    
    if not yesterday_missions_checked(service=service, sheet_id =sheet_id, line=line, column='B'):
        yesterday_check(service, sheet_id, line, offline)
    rotor = RotaryEncoder(17, 18, max_steps=len(activities)-1)
    button = Button(17)   # To debug here, need to add those button fonctions ( maybe pin SW needed ? )
    print("now waiting")
    rotor.wait_for_rotate_clockwise()
    print("End of the waiting")
    loop = 1
    while loop:
        print(rotor.steps)
        print(activities[rotor.steps].name)
        time.sleep(0.2)
コード例 #10
0
ファイル: old_main.py プロジェクト: dlx-designlab/Hataya
from time import sleep
import threading
from gpiozero import RotaryEncoder, AngularServo

# use custom pin-factory to fix servo jitter, make sure pigpio deamon is running: 'sudo pigpiod'
from gpiozero.pins.pigpio import PiGPIOFactory
pigpio_factory = PiGPIOFactory()

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
コード例 #11
0
    from gpiozero import Button, LED, RotaryEncoder
except ImportError as e:
    raise ImportError("You need GPIOZero to use controls. Run with --no-controls to start without controls enabled.") \
        from e

SONG_BREAK_DELAY_SECS = 2

SEEK_STEP = 400000
VOLUME_STEP = 5
PITCH_STEP = 0.01

mod_but = Button(18)
prev_but = Button(23)
next_but = Button(25)
play_but = Button(24)
rotor_enc = RotaryEncoder(13, 19)
rotor_but = Button(26)
next_led = LED(12)
play_led = LED(16)
prev_led = LED(20)
mod_led = LED(21)

player_logger = setup_logger("player", "player.log")


def rotor_clockwise(player: ManagedAudioPlayer) -> None:
    """Callback for volume/pitch control associated with the clockwise rotation of the rotary encoder"""
    if mod_but.is_pressed:
        player_logger.info("Song Pitch Up 1%")
        player.adjust_pitch(PITCH_STEP)
    else:
コード例 #12
0
from time import sleep
import threading
from pythonosc import udp_client

client = udp_client.SimpleUDPClient("192.168.205.40", "12000")


IS_AV_MODE = False

# create a custom pin-factory to fix servo jitter
# more info heere: https://gpiozero.readthedocs.io/en/stable/api_output.html#servo
# and here: https://gpiozero.readthedocs.io/en/stable/api_pins.html
pigpio_factory = PiGPIOFactory()
servo = AngularServo(22, min_angle=-90, max_angle=90, pin_factory=pigpio_factory)

ENCODER = RotaryEncoder(17, 18, max_steps=0) # Rotary encoder 
ENC_SRV_RATIO = 2 # How many encoder steps is one servo angle

# Create a limit switch senseor which detects system misalignment 
button = Button(27)

def servo_control(delay, servo_step):
  # global IS_AV_MODE
  while IS_AV_MODE:
    if servo.angle + servo_step > servo.min_angle and servo.angle + servo_step < servo.max_angle:
      servo.angle += servo_step
      sleep(delay)
    else:
      servo_step *= -1
      sleep(delay)