You can interact with your RaspberryPi's Gpio interface through GpioInterface
.
- Use
$gpio->createReader()
to create a pin reader. - 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:
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
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);
}
}