文書の過去の版を表示しています。
目次
DSair BASIC (DSbasic)
Keywords: BASIC, Programming, 教育, Education, Maker, DIY, interpreter,
DSbasic is a very easy programming solution on your smartphone! This function works in DSair2's webapp on your browser.
DSbasicは、スマートフォン(Android,iOS)上で動作する、鉄道模型制御向けに最適化されたBASIC開発環境です。命令を打ち込んで実行するだけで、お好きな自動運転や、運転支援機能を実現できます。BASICファイルは、
Features
BASIC is very easy programming environment. DSbasic is implemented in Webapp control software. You can control automatically DCC and Marklin Locomotives on your smartphone.
Function
LocAddr is Locomotive address. Default protocol is DCC. If you want to control Marklin's, configure protocol on web app.
Function | Parameter | Notes |
---|---|---|
PWR | TrackPower | ON=1, OFF=0 |
SPD | LocAddr,Speed | LocAddr=0-9999, Speed=0-1023 |
ACC | AccAddr, Direction | diverse=0, straight=1 |
DIR | LocAddr, Direction | FWD=1, REV=2 |
FNC | LocAddr, FuncNo, FuncON/OFF | FuncNo=0-28 |
FNX | LocAddr, FuncNo | FuncNo=0-28 |
MP3PLAY | FileName with Path | MP3PLAY “Horn.mp3” |
MP3STOP | - | MP3STOP |
GETACC | AccAddr(1-2044) | |
getslotaddr | SlotNo(0-3) | 4つのユーザー指定アドレススロットからアドレスを取得します。 |
getslotspd | SlotNo(0-3) | 4つのユーザー指定アドレススロットから速度を取得します。 |
getslotfnc | SlotNo(0-3), FuncNo(0-28) | 4つのユーザー指定アドレススロットからファンクション状態を取得します。 |
S88START | - | |
S88GET | S88Sensor address(1-16) | Supported 1 S88 decoder |
DCPWM | PWMDuty(0-1203) |
The parameters of function mean as the followings.
引数の意味は以下の通りです。
AccAddr | 1-2044 | ポイントアドレス,MM2の場合は1-320 |
LocAddr | 1-9999 | 機関車アドレス,MM2の場合は1-255。 |
FuncNo | 0-28 | ファンクション番号 |
FuncON/OFF | 0-1 | 0=OFF, 1=ON |
Direction | 1-2 | 0 or 1=FWD, 2=REV |
BASIC functions are described in wwwbasic user manual.
BASIC functions
FOR,NEXT,IF,GOTO,END IF,ELSE,WHILE,WEND, PRINT,COLOR,LOCATE,LINE,PAINT RND,INT,SLEEP
Examples
Shuttle train
pwr 1 spd 69,0 fnc 69,0,1 fnc 69,1,1 dir 69,1 mp3play "Horn.mp3" FOR i = 1 to 10 COLOR i, 0 PRINT "Speed=" + i*10 spd 69,i*10 sleep 500 NEXT i FOR i = 1 to 10 COLOR i, 0 PRINT "Speed=" + (100-i*10) spd 69,100-i*10 sleep 500 NEXT i spd 69,0 dir 69,0
Turnout automatic control
if getacc(1)=1 then if getacc(2)=0 then print "route=A" acc 2,1 acc 3,1 end if end if
Locomotive automatic control
連動記事はこちら。
screen(7) print "Start BASIC Shuttle Control" pwr 1 print "Power on" fnc 69,0,1 fnc 69,1,1 print "F0,F1 on" dir 69,1 fnx 69,2 print "Go FWD!" spd 69,0 sleep 6000 spd 69,100 sleep 8000 print "Run 200/1023" spd 69,200 sleep 5000 spd 69,100 sleep 5000 spd 69,0 sleep 3000 print "Stop" dir 69,2 fnx 69,2 print "Go REV!" spd 69,0 sleep 6000 spd 69,100 sleep 8000 print "Run 200/1023" spd 69,200 sleep 5000 spd 69,100 sleep 5000 spd 69,0 sleep 3000 print "STOP! Finish!"
S88 decoder example
S88デコーダのセンサデータを取得し、Roco BR621(Addr.3)の往復運転を行うサンプルです。
Detail: DSair2で自動運転をしてみる
screen(7) s88start pwr 1 print "START S88 Control" dir 3,1 fnc 3,0,1 fnc 3,1,1 fnx 3,2 spd 3,200 while s88get(1)=0 print "RUN!" sleep 1000 wend print "S88 Adr.1 Detected" spd 3,0 sleep 2000 print "REV" dir 3,2 spd 3,200 sleep 12000 spd 3,0 fnc 3,0,0 fnc 3,1,0 print "end." end
Speed based Announce example
This automatic announce program is triggered by slot 1 speed.
screen(7) print "Announce supporter" print "Addr:";getslotaddr(0) print "Speed:";getslotspd(0) state=0 currentspd = getslotspd(0) while 1 sleep(1000) if currentspd<>getslotspd(0) then print "Current Speed is ";getslotspd(0) currentspd = getslotspd(0) end if if state=0 then if getslotspd(0)>512 then state = 1 print "Next Station" mp3play "NextStationAnnounce.mp3" end if end if if state=1 then if getslotspd(0)<100 then state = 0 print "Stop at Station" mp3play "StopStationAnnounce.mp3" end if end if wend end
Hints
Font size / 文字を大きくする
screen(7)コマンドを最初に宣言すると、文字が大きくなります(おおよそ二倍)
screen(7)
Comment / コメント
If you want to use comment, type like the following.
'Comment example 'コメントです
関数・サブルーチンを宣言する
以下の通り、宣言と、実現部を記述すると関数としてコールできます。
DECLARE FUNCTION GetNantoka(n) FUNCTION GetNantoka(n) digits = 1 GetNantoka= digits END FUNCTION
WHILEを使う
以下のように記述できます。
n=100 i=0 WHILE i> 2 i = i+ 1 n = n / 3 WEND
FOR文
FOR文は以下のように使えます。
FOR i = 0 TO 3000 PRINT i; NEXT i
STEPコマンドを使うと、WHILE文を使わなくても上がり方を調整できます。
FOR i = 0 TO 3000 STEP 100 PRINT i; NEXT i
Special Thanks
DSbasic is powered by wwwbasic and Ace text editor.