Example #1
0
    def __init__(self, pin):
        self._value = 0

        # setup gpiozero to call increment on each when_activated
        encoder = DigitalInputDevice(pin)
        encoder.when_activated = self._increment
        encoder.when_deactivated = self._increment
Example #2
0
 def __init__(self, pin):
     self._value = 0
     #GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
     #GPIO.add_event_detect(pin, GPIO.FALLING, callback=self._increment, bouncetime=10)
     encoder = DigitalInputDevice(pin, pull_up=True)
     encoder.when_activated = self._increment
     encoder.when_deactivated = self._increment
Example #3
0
 def initialize(pin, device_type):
     if device_type == "DigitalInput":
         device = DigitalInputDevice(pin)
         device.when_activated = lambda: on_action(pin, 0)
         device.when_deactivated = lambda: on_action(pin, 1)
         pin_map[pin] = device
         print("Initialized pin {} as {}".format(pin, device_type))
     elif device_type == "DigitalOutput":
         pin_map[pin] = DigitalOutputDevice(pin)
         print("Initialized pin {} as {}".format(pin, device_type))
Example #4
0
def create_encoder(pin):
    """
  Creates and configures a DigitialInputDevice at the specified pin for use
  as a rotary encoder input.

  This function is intended for internal use only.
  """
    encoder = DigitalInputDevice(pin, pull_up=True)
    encoder.when_activated = on_change
    encoder.when_deactivated = on_change
    return encoder
Example #5
0
from gpiozero import LineSensor, DigitalInputDevice
from signal import pause
from time import sleep


def found():
    print("hehwerewrewr")


def nofound():
    print("adsadsadsad")


# sensor = LineSensor(4)

# sensor.when_line = found
# sensor.when_no_line = nofound

sensor = DigitalInputDevice(4)

sensor.when_activated = found
sensor.when_deactivated = nofound

sleep(1)

while True:
    print("Sensor value: ", sensor.active_state)
    sleep(1)

#pause()
Example #6
0
    def __init__(self, pin):
        self._value = 0

        encoder = DigitalInputDevice(pin)
        encoder.when_activated = self._increment
        encoder.when_deactivated = self._increment
from gpiozero import DigitalInputDevice
from signal import pause
import time

class encoder(object):
   def __init__(self):
      self.value = 0
   
   def reset(self):
      self.value = 0
   
   def increment(self):
      self.value += 1


def activated()   : my_enc.increment()  
def deactivated() : return 0

my_enc = encoder()

enc = DigitalInputDevice(17)
enc.when_activated = activated
enc.when_deactivated = deactivated

start = time.time()
while True:
   elapsed = time.time()-start 
   print('Time {0:0.2f} -- N = {1} -- Velocity {2}'.format(elapsed,my_enc.value,my_enc.value/elapsed),end="\r")


pause()
Example #8
0
    'frame': 0,
}


def start_frame():
    state['x'] = 0
    state['y'] = 0
    state['frame'] += 1
    print('frame')


def start_line():
    state['y'] += 1
    state['x'] = 0
    print('line')


def clock_pixel():
    print(d0.is_active, d1.is_active, clk.is_active)
    #sys.exit(1)


vsync.when_deactivated = start_frame
hsync.when_deactivated = start_line
clk.when_deactivated = clock_pixel

try:
    pause()
except:
    print(state)
Example #9
0
from messageDecoder import *
from gpiozero import DigitalInputDevice

#sends message to user when pet goes to food bowl.
diginput = DigitalInputDevice(22)


def WhenActivated():
    data = "pet at bowl"
    sendMessageDogDetect(data)


def WhenDeactivated():
    data = "pet left bowl"
    sendMessageDogDetect(data)


diginput.when_activated = WhenActivated
diginput.when_deactivated = WhenDeactivated
def row3Released():
    global scanning
    scanning = True


def row4Released():
    global scanning
    scanning = True


row1.when_activated = row1Pressed
row2.when_activated = row2Pressed
row3.when_activated = row3Pressed
row4.when_activated = row4Pressed
row1.when_deactivated = row1Released
row2.when_deactivated = row2Released
row3.when_deactivated = row3Released
row4.when_deactivated = row4Released

currentMillis = 0
previousMillis = 0
interval = 10
colNumber = 0
keypadNumber = 20
scanning = True
passCount = 0
passTimeout = 0
password = "******"
passEnter = ""
Example #11
0
enc2_rev = 0


def enc1_fn():
    global enc1_clicks, enc1_rev
    enc1_clicks = enc1_clicks + 1

    if enc1_clicks == 40:
        enc1_clicks = 0
        enc1_rev = enc1_rev + 1
        print(enc1_rev, ' Revolutions completed by enc 1')


def enc2_fn():
    global enc2_clicks, enc2_rev
    enc2_clicks = enc2_clicks + 1

    if enc2_clicks == 40:
        enc2_clicks = 0
        enc2_rev = enc2_rev + 1
        print(enc2_rev, ' Revolutions completed enc 2')


enc1.when_activated = enc1_fn
enc1.when_deactivated = enc1_fn

enc2.when_activated = enc2_fn
enc2.when_deactivated = enc2_fn

while True:
    time.sleep(1)
Example #12
0
from sweetmorse.morse import Morse
from gpiozero import DigitalOutputDevice, DigitalInputDevice

speed = 100  # bits per second
cycle_time = 1 / speed  # seconds per bit
end_of_file = "1010101010101010101"

print("Obtaining pin 21 for output...")
gpio_out = DigitalOutputDevice(21)  # voltage generated here

print("Obtaining pin 16 for input...")
print()
gpio_in = DigitalInputDevice(16)  # voltage read here
edges = []  # rising or falling voltage transitions
gpio_in.when_activated = lambda: edges.append((dt.datetime.now(), "1"))
gpio_in.when_deactivated = lambda: edges.append((dt.datetime.now(), "0"))

try:
    message = Morse.from_plain_text("sos")
    binary_outgoing = message.binary

    print("Sending message: " + message.plain_text)
    print("Converted to binary: " + binary_outgoing)
    print()
    print("Sending message at {} bits per second...".format(speed))
    print()

    for value in binary_outgoing + end_of_file:
        if value == '0':
            gpio_out.off()
        else:
Example #13
0
#!/usr/bin/python
import time
import cv2
import requests
from gpiozero import LED, LightSensor, DigitalInputDevice

led = LED(17)
sensor = DigitalInputDevice(4)

sensor.when_activated = led.on
sensor.when_deactivated = led.off

while True:
    time.sleep(1)
Example #14
0
                "value"]:
            values[index_user_changed] = user_changed_value_and_index["value"]
            update_index(index_user_changed,
                         user_changed_value_and_index["index"])
            values[index_auto_change] = auto_changed_value_and_index["value"]
            update_index(index_auto_change,
                         auto_changed_value_and_index["index"])
    else:
        values[index_user_changed] = user_changed_value_and_index["value"]
        update_index(index_user_changed, user_changed_value_and_index["index"])

    update_screen()


button = Button(select_button_pin)
button.when_held = held
button.when_released = released

button_two = Button(select_button_two_pin)
button_two.when_activated = second_button_pressed

clk = DigitalInputDevice(clk_pin, True)
clkLastState = clk.value
dt = DigitalInputDevice(dt_pin, True)

clk.when_deactivated = rot

setup()

pause()
from gpiozero import DigitalInputDevice
from signal import pause


def button_pressed():
    print("pressed")


def button_released():
    print("released")


button_pin = DigitalInputDevice(23, pull_up=True)

button_pin.when_activated = button_pressed

button_pin.when_deactivated = button_released

pause()