LoginSignup
3
2

AtsEXを使用してスイッチで扉の開閉を行おう

Last updated at Posted at 2023-12-30

5速AT (おーとま) さんが開発中の AtsEXプラグイン により BVE の機能拡張が可能になりました。

image.png
今回は 都市型ワンマンプラグイン を使用してドア開閉を行ってみます。
なお、今回紹介するプラグインはβ版になります。(2023年12月現在)

AtsEXプラグインのインストール

最初に AtsEXプラグイン をインストールしましょう。

まずは、ダウンロードします。
image.png
AtsEXプラグインをインストールします。
インストーラーにより簡単に導入できるようになりました。
詳細情報 をクリックします。
image.png
実行 をクリックします。
image.png
次へ をクリックします。
image.png
今回は、BVE5に入れるため スキップ をクリックします。
image.png
はい をクリックします。
image.png
BVE5を立ち上げた状態で 自動検出 をクリックします。
image.png
プロセス名に起動しているBVE5が表示されます。
選択 をクリックします。
** プロセス名に表示されていない場合は、 最新情報に更新 をクリックします。
image.png
次へ をクリックします。
image.png
シナリオフォルダ を選択し、次へ をクリックします。
image.png
インストールを開始 をクリックします。
image.png
起動しているBVE5を終了させるか確認されますので、OK をクリックします。
image.png

インストールが終了したので、 完了 をクリックします。

起動する

BVEを起動します。

都市型ワンマンプラグインのインストール

次に、都市型ワンマンプラグイン をインストールします。
image.png
Github から最新のZIPファイルを ダウンロード します。

image.png
ZIPファイルから該当のフォルダとファイルを、車両ファイル にコピーします。
image.png
image.png
CityOneman.dll はそのままではブロックされてしまうため、許可 をします。
右クリック⇒プロパティ
image.png
セキュリティ⇒許可する を選択し、OK をクリックします。
image.png
以上で、都市型ワンマンプラグイン が使用できるようになりました。

 都市型ワンマンプラグインの設定ファイルの文法

設定ファイルの文法 にあるように CityOneman.Config.xml の以下が キーアサイン になります。

    <Keys>
      <LeftOpen KeyCode="E" />
      <LeftClose KeyCode="R" />
      <LeftReopen KeyCode="T" />
      <RightOpen KeyCode="O" />
      <RightClose KeyCode="I" />
      <RightReopen KeyCode="U" />
    </Keys>

Raspberry Pi Picoでキースイッチを作る

Raspberry Pi Pico を使用してキースイッチを作ってみましょう。
再開閉ボタン や、ホーン は、長押しをするために

Keyboard.press
Keyboard.release

と記述します。

プログラム

コード全容

/*
  Button to HID Custom!
  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button
*/
#include "Keyboard.h"

// constants won't change. They're used here to set pin numbers:
const int Button2 = 2;    // the number of the pushbutton pin
const int Button3 = 3;    
const int Button4 = 4;    
const int Button5 = 5;    
const int Button6 = 6;    
const int Button7 = 7;    
const int Button8 = 8;    
const int Button9 = 9;    
const int Button10 = 10;  

// variables will change:
int buttonState2 = 0;       // variable for reading the pushbutton status
int buttonState2_old = 0;   // variable for reading the pushbutton status
int buttonState3 = 0;       // variable for reading the pushbutton status
int buttonState3_old = 0;   // variable for reading the pushbutton status
int buttonState4 = 0;       // variable for reading the pushbutton status
int buttonState4_old = 0;   // variable for reading the pushbutton status
int buttonState5 = 0;       // variable for reading the pushbutton status
int buttonState5_old = 0;   // variable for reading the pushbutton status
int buttonState6 = 0;       // variable for reading the pushbutton status
int buttonState6_old = 0;   // variable for reading the pushbutton status
int buttonState7 = 0;       // variable for reading the pushbutton status
int buttonState7_old = 0;   // variable for reading the pushbutton status
int buttonState8 = 0;       // variable for reading the pushbutton status
int buttonState8_old = 0;   // variable for reading the pushbutton status
int buttonState9 = 0;       // variable for reading the pushbutton status
int buttonState9_old = 0;   // variable for reading the pushbutton status
int buttonState10 = 0;      // variable for reading the pushbutton status
int buttonState10_old = 0;  // variable for reading the pushbutton status

void setup() {
  pinMode(Button2, INPUT_PULLUP);
  pinMode(Button3, INPUT_PULLUP);
  pinMode(Button4, INPUT_PULLUP);
  pinMode(Button5, INPUT_PULLUP);
  pinMode(Button6, INPUT_PULLUP);
  pinMode(Button7, INPUT_PULLUP);
  pinMode(Button8, INPUT_PULLUP);
  pinMode(Button9, INPUT_PULLUP);
  pinMode(Button10, INPUT_PULLUP);
  Keyboard.begin();
}

void loop() {
  // read the state of the pushbutton value:
  buttonState2 = digitalRead(Button2);
  if (buttonState2 != buttonState2_old) {
    // check if the pushbutton is pressed. If it is, the buttonState is LOW:
    if (buttonState2 == LOW) {
      // Keyboard Write:
      Keyboard.write('e');
    }
  }
  buttonState3 = digitalRead(Button3);
  if (buttonState3 != buttonState3_old) {
    if (buttonState3 == LOW) {
      Keyboard.write('r');
    }
  }
  buttonState4 = digitalRead(Button4);
  if (buttonState4 != buttonState4_old) {
    if (buttonState4 == LOW) {
      Keyboard.press('t');
    } else  {
      Keyboard.release('t');
    }
  }
  buttonState5 = digitalRead(Button5);
  if (buttonState5 != buttonState5_old) {
    if (buttonState5 == LOW) {
      Keyboard.write('o');
    }
  }
  buttonState6 = digitalRead(Button6);
  if (buttonState6 != buttonState6_old) {
    if (buttonState6 == LOW) {
      Keyboard.write('i');
    }
  }
  buttonState7 = digitalRead(Button7);
  if (buttonState7 != buttonState7_old) {
    if (buttonState7 == LOW) {
      Keyboard.write('u');
    }
  }
  buttonState8 = digitalRead(Button8);
  if (buttonState8 != buttonState8_old) {
    if (buttonState8 == LOW) {
      Keyboard.write(0xDE);
    }
  }
  buttonState9 = digitalRead(Button9);
  if (buttonState9 != buttonState9_old) {
    if (buttonState9 == LOW) {
      Keyboard.press(KEY_RETURN);
    } else  {
      Keyboard.release(KEY_RETURN);
    }
  }
  buttonState10 = digitalRead(Button10);
  if (buttonState10 != buttonState10_old) {
    if (buttonState10 == LOW) {
      Keyboard.press(0xDF);
    } else {
      Keyboard.release(0xDF);
    }
  }
  buttonState2_old = buttonState2;
  buttonState3_old = buttonState3;
  buttonState4_old = buttonState4;
  buttonState5_old = buttonState5;
  buttonState6_old = buttonState6;
  buttonState7_old = buttonState7;
  buttonState8_old = buttonState8;
  buttonState9_old = buttonState9;
  buttonState10_old = buttonState10;
  delay(100);
}

以上で、ATSex を手元のスイッチで使用できるようになったと思います。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2