MegaGumbo wrote:The !PiLed example works now, but will the module be present after a reboot?
No, you need to load the module after every reset/boot.
This can be automated though.
If you shift double click on !Boot, double click on Choices, double click on Boot, double click on PreDesk, then copy the GPIO module there. It will then load automatically.
OR
Double click !Boot, Click Boot, Click Run, drag the module to the open window, click Set, click Set.
There are other ways, but these are the simplest.
stylx wrote:Using Tanks module. if download tanks module , unzip it and then load the module with
*RMLoad GPIO
Because I only using a floppy cable and and three Leds I was prompted to use GPIO pins 7,10,22 for ease of use.Plug you leds into gpio pin and then run tanks !GPIOConfi program then hightlight the GPIO pins until they turn green then to test switch then on and the leds should come to life, now switch then off again but leave the box so it still as a green square around it then enter the program below.
REM > TEST
ON ERROR REPORT : PRINT " at line ";ERL:END
DIM light%(4)
FOR array%=0 TO 4
READ light%(array%)
DATA 7,10,22,10,7
NEXT
:
FOR x%=0 TO 10000
FOR y%=0 TO 4
LET led%= light%(y%)
PRINT led%
PROCon (led%)
PROCoff (led%)
NEXT
NEXT
:
END
:
DEFPROC (led%)
FOR x%= 0 TO 2000
SYS "GPIO_WriteData",led%,-1
NEXT
ENDPROC
:
DEFPROCoff (led%)
FOR x%= 0 to 2000
SYS "GPIO_WriteData",led%,0
NEXT
ENDPROC
run this program and the leds should flash in sequence, by changing the order in the data statement you change the order led flash.
I know this is a bit rudementary and you have to use tanks module TO initilise the leds to begin with but it works, I try to get Tank to give me a 101 on the module ,but that a no go. I looking at tank module and hope to work out how to initialise GPIO pins from Basic and maybe then I could do a lot more. But somthing tells me I got to learn machine code to make the GPIO pin do what I want then to
Sorry I didn't get to help earlier. Up till now most people using this module have been diehard RISC OS users, who already know quite a lot about how to use modules ETC.
One question I have about your BASIC program, why to you call the "GPIO_WriteData" 2000 times in your PROC's ?
If this is just to get a delay, call the SWI first, then do the delay loop. The SWI's set the output to the requested level until you request a change.
The same with your later change, The GPIO_Mode only needs to be called once at the start of the program as it sets the mode until you change it again.
Try this instead.
REM > TEST
ON ERROR REPORT : PRINT " at line ";ERL:END
DATA 7,10,22,10,7
:
REM set pins as output (1=output 0 =input)
FOR a%=1 TO 3
READ led%
SYS "GPIO_WriteMode",led%,1
NEXT
:
REM do this forever, press escape to get out
REPEAT
RESTORE
FOR y%=1 TO 5
READ led%
REM turn it on
SYS "GPIO_WriteData",led%,1
REM delay
FOR x%= 0 TO 2000
NEXT
REM turn it off
SYS "GPIO_WriteData",led%,0
REM add another delay here to have a gap before the next LED lights
NEXT
UNTIL FALSE
:
END
(Untested but SHOULD work!!!)