Free Pascal => Beginners => Topic started by: MadMike on October 22, 2020, 01:51:03 pm

Title: (Solved)Pascalio/GPio access on a Raspberry Pi, again.
Post by: MadMike on October 22, 2020, 01:51:03 pm

Hopefully this won't take up much of your time. I'm a complete noob at this software stuff. Much more at home with a few chips and a reel of solder.

I'm trying to use the GPIO on a Raspberry to address some external hardware and then read the state of this hardware on another GPIO.

I've successfully used the FGPIO unit from Pascalio to individually write OR read to a SINGLE pin. That's fine.

But this below doesn't work:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   Switch:= TGpioLinuxPin.Create(4);
  4.   LED.Direction:= gdIn;
  6.   Led:= TGpioLinuxPin.Create(18);
  7.   Led.Direction:= gdOut;
  8. end;
  10. procedure TForm1.Button1Click(Sender: TObject);
  11. begin
  12.   Led.Value:= true;
  13.   Shape1.brush.color:= clLime;
  14. end;
  16. procedure TForm1.Button2Click(Sender: TObject);
  17. begin
  18.   Led.Value:= false;
  19.   Shape1.Brush.Color:= clWhite;
  20. end;
  22. procedure TForm1.Button3Click(Sender: TObject);
  23. begin
  24. //  if Switch.Value = true then Shape2.brush.color:= clRed
  25.  // else Shape2.Brush.Color:= clBlue;
  26. end;
  28. procedure TForm1.FormDestroy(Sender: TObject);
  29. begin
  30.   Led.Free;
  31.   Switch.Free;
  32. end;
  34. end.

I've since realised that the second 'create' overwrites the first instance.

My question is how can I initialise many pins at once?

This was most useful at first, and seems to indicate I may need to pin the needed GPIO's in an array somehow: (

All answers gratefully received.


Title: Re: Pascalio/GPio access on a Raspberry Pi, again.
Post by: MadMike on October 22, 2020, 03:29:43 pm
Sorry fellas,

Just noticed the typo.

Works now...

TinyPortal © 2005-2018