MMB4L: MMBasic for Linux alpha release


Author Message
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3094
Posted: 11:18pm 23 Sep 2021      

This is a kludge pending incorporation of pin I/O into the firmware (if that happens), but here is

Digital output to pins on a Pi Zero W with MMB4L:

Youtube: LEDs on and off

' PiIO.bas performs digital I/O with linux4MMB
'
dim integer i,j,k,p(16)=(0,26,19,13,6,5,0,11,9,10,17,22,27,12,16,20,21)
dim integer pState(16)
dim integer q(4)=(0,14,15,18,23), dout=1, din=0

for i=1 to 16
 setpin p(i),dout
next
for i=1 to 4
 setpin p(i),din
next

i=1
do
 pState(i)=1-pState(i) ' toggle state
 cmd$="sudo echo '"+str$(pState(i))+"' > /sys/class/gpio/gpio"+str$(p(i))+"/value"
'  print cmd$
 system(cmd$)
 inc i: if i > 16 then i=1
 pause 500
loop

sub setpin(pinno as integer, pinmode as integer)
 local string dirname$, cmd$
 dirname$="/sys/class/gpio/gpio"+str$(pinno)
 if not MM.INFO(EXISTS DIR dirname$) then
   cmd$="sudo echo '"+str$(pinno)+"' > /sys/class/gpio/export 2>/dev/null"
'    print cmd$
   system cmd$
 endif
 if pinmode then
   cmd$="sudo echo 'out' > "+dirname$
 else
   cmd$="sudo echo 'in' > "+dirname$
 endif
end sub


A minor point: artifacts in screen when up-arrow to re-run command (but very happy to have that feature):

> edit
run
> redit
ererun                                                                        
> redit
erun                                                                          


This uses BigMik's freeware 2x20 breakout Proto Board.

Congratulations, Thwill. Nice work. I look forward to exploring.