ユーザ用ツール

サイト用ツール


dsair2_basic

文書の過去の版を表示しています。


DSair BASIC (DSbasic)

Keywords: BASIC, Programming, 教育, Education, Maker, DIY, interpreter,

DSair2 (English) (JPN)

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ファイルは、SDカードに置けば、ファイル一覧からロードできます。修正したプログラムは、スマホのメモリに保存できます。


Large Image

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.

  • BASIC language powered by wwwbasic BASIC interpreter engine.
  • Works in smartphone's browser
  • Seperated Editor and Display. Easy to use.
  • ACE based powerful text editor on browser.
  • Support Locomotive and Turnouts control via BASIC language
  • MP3 Play suported in MP3 files of FlashAir SD card.

BASIC Function

DSair2 Unique Functions

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, FuncON/OFF=0(OFF) or 1(ON)
FNX LocAddr, FuncNo FuncNo=0-28,ファンクションのOFF→ON→ON操作をします。
MP3PLAY FileName with Path MP3PLAY “Horn.mp3”
MP3STOP - MP3STOP
GETACC AccAddr(1-2044) 指定アドレスのポイント状態(0=div, or 1=str)を返します。
GETACCW AccAddr(1-2044) 指定アドレス以降16個分のポイント状態(0=div, or 1=str)を返します。
getslotaddr SlotNo(0-3) 4つのユーザー指定アドレススロットからアドレスを取得します。
getslotspd SlotNo(0-3) 4つのユーザー指定アドレススロットから速度を取得します。
getslotfnc SlotNo(0-3), FuncNo(0-28) 4つのユーザー指定アドレススロットからファンクション状態(0=OFF,1=ON)を返します。
getslotfncw SlotNo(0-3) 4つのユーザー指定アドレススロットからファンクション状態を29bit分返します。
S88START - S88機能を有効にします。S88の関数を使う場合は必ずBASICプログラムの最初に記述して下さい。括弧はつけないでください。
S88GET,GETS88 S88Sensor address(1-16) S88センサーの値(0=OFF,1=ON)を返します。
GETS88W S88Sensor address(1-16) S88センサーの値を16bit分返します。
DCPWM PWMDuty(0-1203)
DCDIR Direction FWD=1, REV=2

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.

Main functions

FOR,NEXT,IF,GOTO,END IF,ELSE,WHILE,WEND,

Drawing functions

  • PRINT
  • COLOR
  • LOCATE
  • LINE
  • PAINT
  • CIRCLE
  • PUT
  • SCREEN
  • CLS
  • WIDTH
  • PALETTE

Math functions

asc, sqr, int, cint abs, cos, sin, tan atn, exp, log, rnd, atan2

Text functions

  • val 文字を数値に変換
  • str$ 数値を文字列に変換
  • ltrim$ 左側文字列を抜き出す
  • rtrim$ 右側文字列を抜き出す
  • left$
  • right$
  • mid$
  • string$
  • space$ スペースを抜き出す
  • tab
  • ucase$ 英字を大文字にする
  • lcase$ 英字を小文字にする
  • mid$

Key Input functions

  • inkey$
  • input

Mouse Input functions

  • getmouse

Etc functions

  • timer
  • SLEEP
  • swap

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.

DSbasicで運転支援機能

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.

dsair2_basic.1552948773.txt.gz · 最終更新: 2019/03/19 07:39 by yaasan

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki