Skip to content

Pingo.jl #1

@s-celles

Description

@s-celles

Pingo.jl

An input/output library based on https://github.com/aviks/PiGPIO.jl (for RaspberryPi)
but that could be use for other board also

inspired by https://github.com/pingo-io/pingo-py

and https://github.com/RPi-Distro/python-gpiozero/

A possible "parts" (just led) API usage might be

using Pingo

board = Board()  # or Board('rpi')
pin = Pin(board, 17)  # should we use BCM or BOARD numbering ? probably BCM
# pin = Pin(board, BCM(17))
led = Led(pin)
while true
    on(led)  # or switch_on(led)
    sleep(1)
    off(led)  # or switch_off(led)
    sleep(1)
end

pin might be an integer or a DigitalPin
board shouldn't be necessary (if no board is given we should use a DefaultBoard object)

An example with led and button

board = Board()
led = Led(board, 17)
button = Button(board, 3)

while true
    if ispressed(button)
        on(led)
    else
        off(led)
    end
    sleep(0.01)
end

an other (maybe harder to implement) might be

board = Board()
led = Led(board, 17)
button = Button(board, 3)

# make_callback(when_pressed, button, led, on)  # or make_callback(button, when_pressed, led, on) 
# make_callback(when_released, button, led, off)

# connect(button, when_pressed, led, on)
# connect(button, when_released, led, off)

button.when_pressed = () -> on(led)
button.when_released = () -> off(led)

wait_events()

with

function wait_events(; delay=0.01)
    while true
        sleep(delay)
    end
end

keywords: callback ; event driven programming ; signal slot ; publish subscribe ; pattern ; dispatch module ; observer pattern ; message ; messaging ; dispatching

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions