Skip to content

Instantly share code, notes, and snippets.

@hekras
Created February 10, 2023 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hekras/44ffcab88cc1fa5ca3cfbbf0fbf46719 to your computer and use it in GitHub Desktop.
Save hekras/44ffcab88cc1fa5ca3cfbbf0fbf46719 to your computer and use it in GitHub Desktop.
option explicit
open "COM2:9600" AS #2
controller nunchuk open
mode 1, 8
dim current_turnout=0
dim nunchuk_trigger
dim oldk$ = ""
dim d,n,m,x,y,p,t,bordercolor,jx,jy,ca,cb
dim a$, k$
dim shortcut$ = "qQaAwWsSeEdDrRfFtTgGyYhHuUjJiIkK";
dim turnout_pos(17)
init_all_points()
nunchuk_trigger=0
page write 1
do
page copy 1 to 0
cls
box 0, 570, 800, 30, 1, rgb(0,0,255), rgb(0,0,255)
box 0, 0, 800, 15, 1, rgb(125,125,125), rgb(125,125,125)
text 1,2,"Rails"
d = 800/8
for n=0 to 8
for m=0 to 1
x = 10+n*100
y = 370+m*100
p = 22+n*4+m*2
t = n*2+m
bordercolor = choice(t=current_turnout, rgb(255,255,0), rgb(155,155,255))
box x, y, 80, 80, 5, bordercolor, rgb(0,0,255)
text x+40,y+10,"H"+str$(n+1)+", P"+str$(m+1), "C", , ,rgb(255,255,0), rgb(0,0,255)
text x+40,y+22,"("+str$(p)+"+"+str$(p+1)+")", "C", , ,rgb(255,255,0), rgb(0,0,255)
text x+40,y+34,mid$(shortcut$,2+t*2,1), "C", , ,rgb(0,0,0), rgb(255,255,255)
ca=choice(turnout_pos(t) = 0, rgb(255,255,155),rgb(0,0,0))
cb=choice(turnout_pos(t) = 0, rgb(0,0,0),rgb(255,255,155))
line x+20,y+65,x+60,y+65,,ca
line x+20,y+70,x+60,y+70,,ca
line x+25,y+65,x+60,y+53,,cb
line x+25,y+70,x+60,y+58,,cb
next m,n
y = nunchuk(Z)
jx = nunchuk(JX)
jy = nunchuk(JY)
if (jx > 128) and (nunchuk_trigger=0) and (current_turnout < 15) then
inc current_turnout, 1
inc nunchuk_trigger, 1
else if jx < 128 and nunchuk_trigger=0 and current_turnout > 0 then
inc current_turnout, -1
inc nunchuk_trigger, 1
else if y=1 and nunchuk_trigger=0 then
turnout_pos(current_turnout) = abs(turnout_pos(current_turnout)-1)
switchpoint(current_turnout)
inc nunchuk_trigger, 1
else if jx=128 and y=0 then
nunchuk_trigger = 0
endif
text 580,2," "+str$(y)+" ", "C"
text 480,2," "+str$(jy)+" ", "C"
text 380,2," "+str$(jx)+" ", "C"
x = keydown(1)
k$ = chr$(x)
n = instr(1,shortcut$,k$)
if n>1 then current_turnout=fix((n-1)/2)
a$ = input$(1, #2)
if a$<>"" then print a$
if x=128 then
turnout_pos(current_turnout) = 1
switchpoint(current_turnout)
else if x=129 then
turnout_pos(current_turnout) = 0
switchpoint(current_turnout)
endif
if k$<>oldk$ then
text 680,2," "+str$(x)+" ", "C"
text 650,2," "
text 650,2,k$
oldk$ = k$
endif
text 750,2,time$, "C"
loop while x<>148
end
sub init_all_points()
local m
for m=0 to 15
turnout_pos(m) = 1
switchpoint(m)
next m
end sub
sub switchpoint(point)
local arduinoport
arduinoport = point * 2 + 22
print #2, "$"+str$(arduinoport)+" "+str$(turnout_pos(current_turnout))+"!"
print #2, "$"+str$(arduinoport+1)+" "+str$(abs(turnout_pos(current_turnout)-1))+"!"
end sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment