Skip to content

Latest commit

 

History

History
executable file
·
43 lines (33 loc) · 1.47 KB

RaspberryPi.md

File metadata and controls

executable file
·
43 lines (33 loc) · 1.47 KB

RaspberryPi

You can interact with your RaspberryPi's Gpio interface through GpioService.

The service provides two methods: createReader() and createWriter().

Both take one argument, the pin.

The pin is a string that can have one of the following values: 7, 11, 12, 13rv1, 13, 13rv2, 15, 16, 18, 22.
Pin 13 is an alias for 13rv2, meaning internally its index is resolved to 27.

As you can see they're named following the pins' indexing as show in this schema: gpio1

This way you can physically count the pins' position if you don't have the schema around and don't remember it.

Here's an example of a blinking LED on pin 12
image

<?php
use CatPaw\Core\Unsafe;
use function Amp\delay;
use function CatPaw\Core\error;
use function CatPaw\Core\anyError;
use CatPaw\Core\RaspberryPi\Services\GpioService;

function main(GpioService $gpio): Unsafe {
    return anyError(function() use($gpio) {
        $writer = $gpio->createWriter('12');
        $active = true;
        while (true) {
            $writer->write($active?'1':'0')->try();
            $active = !$active;
            delay(1);
        }
    });
}

ezgif-7-8019444815