First off I'd like to second that Lazarus is really light weight.
However since I'm new to both Pascal and Lazarus I have not got around to do actual coding in Lazarus (its on my todo list).
I've written everything in Nano and compiled with "fpc <program>" directly on the RPi and launching with "./<program>".
Here are the units i have created to make
my life easier. (It probably looks like crap to experienced programmers)
You can use it as an example or straight up if you find it sufficient for your needs.
Basically my example contains 3 units:
- GVL.pas: "Global variable list", i use it in the program/sub-units to access the GPIO globaly with "GVL.GPIO[17]" for example.
With this you need to call procedures "GVL.readInputs()" before using the inputs and "GVL.setOutputs()" to set the outputs. When terminating the application you would use the "GVL.unexportGPIO()" to restore the GPIO again.
- iolist.pas: This is the I/O-list i use to map the individual GPIO's as input/output. This is the basis for the last module.
- IO_GPIO.pas: This is the actual "driver" based on the /sys example in the wiki. This one contains procedures used by GVL.pas.
Example how to use:
program main(input, output);
{$mode objfpc}{$H+}
uses
..., GVL;
begin
repeat // Loop
GVL.readInputs(); // Read the inputs defined in iolist.pas
if GVL.GPIO[17] then // Use GPIO 17
begin
GVL.GPIO[18] := true; // Set GPIO 18
end;
GVL.setOutputs(); // Set the output state of GPIO's defined in iolist.pas
until not GVL.GPIO[20] // Escape loop
GVL.unexportGPIO(); // Unexport/free the GPIO from /sys upon program termination
end.
Edit: Spelling mistake.
I forgot to mention: my setup is positive voltage to GPIO input = TRUE. Output TRUE = positive voltage on GPIO pin. This can be switched in the IO_GPIO.pas unit.