Example #1
0
    def __init__(self, digits, segments):
        self.digits = digits
        self.segments = segments
        self.window_size = len(digits)

        lines = self.digits + self.segments
        defaults = ((1, ) * len(self.digits) + (0, ) * len(self.segments))
        GPIOHandle.__init__(
            self,
            lines,
            defaults=defaults,
            mode="out",
        )
        self.state = None
Example #2
0
class Sonar():

    def __init__(self, echo_pin, trigger_pin):
        self.echo_pin = echo_pin
        self.trigger_pin = trigger_pin

        self.trigger_handle = GPIOHandle((self.trigger_pin,), mode="out")
        self.echo_handle = GPIOEventHandle(self.echo_pin, mode="both")

    def trigger(self):
        self.trigger_handle.flip()
        self.trigger_handle.flip()

    def measure(self):
        self.trigger()
        start = self.echo_handle.get()[0]
        print("Start", start)
        stop = self.echo_handle.get()[0]
        print("Stop", stop)

        return (stop - start)*340.0/2.0
Example #3
0
import os
import json
import asyncio
from aiohttp.web import (Application, Response, WebSocketResponse, WSMsgType,
                         run_app, FileResponse)

from gpiodev import GPIOHandle

HOST = os.getenv('HOST', '0.0.0.0')
PORT = int(os.getenv('PORT', 8080))

# GPIO pin numbers for your board
GPIO_LINES = (18, 4)

gpio_led = GPIOHandle(GPIO_LINES, mode="out")


async def index_handler(request):
    '''
    send static index file
    '''
    return FileResponse('./static/index.html')


async def websocket_handler(request):
    '''
    use websocket to handle button clicks/LED changes
    '''
    resp = WebSocketResponse()
    ok, protocol = resp.can_prepare(request)
    if not ok:
Example #4
0
    def __init__(self, echo_pin, trigger_pin):
        self.echo_pin = echo_pin
        self.trigger_pin = trigger_pin

        self.trigger_handle = GPIOHandle((self.trigger_pin,), mode="out")
        self.echo_handle = GPIOEventHandle(self.echo_pin, mode="both")
Example #5
0
from gpiodev import GPIOHandle
import time

RedLED = GPIOHandle((19, ), mode="out")
Button = GPIOHandle((18, ), mode="in")

while True:

    state = Button.get_values()[0]
    print(state)
    RedLED.set_values((state, ))
    time.sleep(0.1)
from gpiodev import GPIOHandle
import time

RedBlueLED = GPIOHandle((26, 21))

print(RedBlueLED.get_values())

states = [
    (1, 0),
    (0, 1),
    (1, 1),
]

for state in states:
    RedBlueLED.set_values(state)
    print(RedBlueLED.get_values())
    time.sleep(5)