Skip to content

Latest commit

 

History

History
executable file
·
37 lines (27 loc) · 1.37 KB

RaspberryPi.md

File metadata and controls

executable file
·
37 lines (27 loc) · 1.37 KB

RaspberryPi

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

  1. Use $gpio->createReader() to create a pin reader.
  2. Use $gpio->createWriter() to create a pin writer.

Both methods 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

use function Amp\delay;
use CatPaw\RaspberryPi\Interfaces\GpioInterface;

function main(GpioInterface $gpio):void {
    $writer = $gpio->createWriter('12');
    $active = true;
    while (true) {
        $writer->write($active?'1':'0')->unwrap($error) or die($error);
        $active = !$active;
        delay(1);
    }
}

ezgif-7-8019444815