概要

親ページの通り、Arduinoを用いてBVEを操作する方法を紹介します。

BVEのデフォルト設定では、TS controler用の入力デバイスプラグインが入っています。それではTS controlerしか動かせない(動かそうと思えばできるかも?)ので、今回は別のプラグインを用います。一から作るのはさすがに厳しいので、Tetsu Otterさんが公開しているGIPIを用います。

今回の場合、図示すると、
ロータリースイッチ→Arduino→GIPI→BVE
となります。

本ページで取り扱うのは、Arduino部分のプログラムになります。

基本的な構文

本ページではGIPIの導入を前提として進めていきます。

Serial.print

編集中です。

スケッチ例

//本番スケッチ

const int B9T = 48;
const int B8T = 46;
const int B7T = 44;
const int B6T = 42;
const int B5T = 40;
const int B4T = 38;
const int B3T = 36;
const int B2T = 34;
const int B1T = 32;
const int B0T = 30;
const int P0T = A0;
const int P1T = A1;
const int P2T = A2;
const int P3T = A3;
const int P4T = A4;
const int P5T = A5;
const int H1T = A11;
const int H2T = A12;
const int H3T = A13;
const int H4T = A14;
const int H5T = A15;
const int FWDT = A7;
const int BCKT = A6;
const int K1T = 49;//ATS確認Space       0x20
const int K2T = 47;//警報リセットInsert 0xD1
const int K3T = 45;//EBリセットDelete   0xD4
const int K4T = 43;//復帰Home           0xD2
const int K6T = 41;//定速Back           0xB2

float currentP = 0;
float beforeP = 0;
float currentB = 0;
float beforeB = 0;
float currentR = 2;
float beforeR = 2;
bool currentK1 = HIGH;
bool beforeK1 = HIGH;
bool currentK2 = HIGH;
bool beforeK2 = HIGH;
bool currentK3 = LOW;
bool beforeK3 = LOW;
bool currentK4 = HIGH;
bool beforeK4 = HIGH;
bool currentK6 = HIGH;
bool beforeK6 = HIGH;

//int countnum = 0;



void setup() {
  Serial.begin(9600);
  while (!Serial);
  pinMode(B9T, INPUT_PULLUP);
  pinMode(B8T, INPUT_PULLUP);
  pinMode(B7T, INPUT_PULLUP);
  pinMode(B6T, INPUT_PULLUP);
  pinMode(B5T, INPUT_PULLUP);
  pinMode(B4T, INPUT_PULLUP);
  pinMode(B3T, INPUT_PULLUP);
  pinMode(B2T, INPUT_PULLUP);
  pinMode(B1T, INPUT_PULLUP);
  pinMode(B0T, INPUT_PULLUP);
  pinMode(P0T, INPUT_PULLUP);
  pinMode(P1T, INPUT_PULLUP);
  pinMode(P2T, INPUT_PULLUP);
  pinMode(P3T, INPUT_PULLUP);
  pinMode(P4T, INPUT_PULLUP);
  pinMode(P5T, INPUT_PULLUP);
  pinMode(H1T, INPUT_PULLUP);
  pinMode(H2T, INPUT_PULLUP);
  pinMode(H3T, INPUT_PULLUP);
  pinMode(H4T, INPUT_PULLUP);
  pinMode(H5T, INPUT_PULLUP);
  pinMode(K1T, INPUT_PULLUP);
  pinMode(K2T, INPUT_PULLUP);
  pinMode(K3T, INPUT_PULLUP);
  pinMode(K4T, INPUT_PULLUP);
  pinMode(K6T, INPUT_PULLUP);
  pinMode(FWDT, INPUT_PULLUP);
  pinMode(BCKT, INPUT_PULLUP);
}

void loop() {
  int B9R = digitalRead(B9T);
  int B8R = digitalRead(B8T);
  int B7R = digitalRead(B7T);
  int B6R = digitalRead(B6T);
  int B5R = digitalRead(B5T);
  int B4R = digitalRead(B4T);
  int B3R = digitalRead(B3T);
  int B2R = digitalRead(B2T);
  int B1R = digitalRead(B1T);
  int B0R = digitalRead(B0T);
  int P0R = digitalRead(P0T);
  int P1R = digitalRead(P1T);
  int P2R = digitalRead(P2T);
  int P3R = digitalRead(P3T);
  int P4R = digitalRead(P4T);
  int P5R = digitalRead(P5T);
  int H1R = digitalRead(H1T);
  int H2R = digitalRead(H2T);
  int H3R = digitalRead(H3T);
  int H4R = digitalRead(H4T);
  int H5R = digitalRead(H5T);
  int K1R = digitalRead(K1T);
  int K2R = digitalRead(K2T);
  int K3R = digitalRead(K3T);
  int K4R = digitalRead(K4T);
  int K6R = digitalRead(K6T);
  int FWDR = digitalRead(FWDT);
  int BCKR = digitalRead(BCKT);
  
  
//  digitalWrite(13, LOW);


//ブレーキ書き直し
  if (B9R == LOW){
    currentB = 9;
  } if (B8R == LOW){
    currentB = 8;
  } if (B7R == LOW){
    currentB = 7;
  } if (B6R == LOW){
    currentB = 6;
  } if (B5R == LOW){
    currentB = 5;
  } if (B4R == LOW){
    currentB = 4;
  } if (B3R == LOW){
    currentB = 3;
  } if (B2R == LOW){
    currentB = 2;
  } if (B1R == LOW){
    currentB = 1;
  } if (B0R == LOW){
    currentB = 0;
  }
  if (currentB != beforeB){
    if (currentB == 9){
      Serial.print("TOB9\r");
    } if (currentB == 8){
      Serial.print("TOB8\r");
    } if (currentB == 7){
      Serial.print("TOB7\r");
    } if (currentB == 6){
      Serial.print("TOB6\r");
    } if (currentB == 5){
      Serial.print("TOB5\r");
    } if (currentB == 4){
      Serial.print("TOB4\r");
    } if (currentB == 3){
      Serial.print("TOB3\r");
    } if (currentB == 2){
      Serial.print("TOB2\r");
    } if (currentB == 1){
      Serial.print("TOB1\r");
    } if (currentB == 0){
      Serial.print("TOB0\r");
    }
  beforeB = currentB;
  }

//ノッチ書き直し
  if (H5R == LOW){
    currentP = 15;
  } if (H4R == LOW){
    currentP = 14;
  } if (H3R == LOW){
    currentP = 13;
  } if (H2R == LOW){
    currentP = 12;
  } if (H1R == LOW){
    currentP = 11;
  } if (P1R == LOW){
    currentP = 1;
  } if (P2R == LOW){
    currentP = 2;
  } if (P3R == LOW){
    currentP = 3; 
  } if (P4R == LOW){
    currentP = 4;
  } if (P5R == LOW){
    currentP = 5;
  } if (P0T == LOW){
    currentP = 0;
  }
  if (currentP != beforeP){
    if (currentP == 15){
      Serial.print("TOH5\r");
    } if (currentP == 14){
      Serial.print("TOH4\r");
    } if (currentP == 13){
      Serial.print("TOH3\r");
    } if (currentP == 12){
      Serial.print("TOH2\r");
    } if (currentP == 11){
      Serial.print("TOH1\r");
    } if (currentP == 1){
      Serial.print("TOP1\r");
    } if (currentP == 2){
      Serial.print("TOP2\r");
    } if (currentP == 3){
      Serial.print("TOP3\r");
    } if (currentP == 4){
      Serial.print("TOP4\r");
    } if (currentP == 5){
      Serial.print("TOP5\r");
    } if (currentP == 0){
      Serial.print("TOP0\rTOH0\r");
    }
  beforeP = currentP;
  }

//キーボード
  currentK1 = K1R;
  if (currentK1 != beforeK1){
    if (currentK1 == LOW){
      Serial.print("TOK1D\r");
    } else {
      Serial.print("TOK1U\r");
    }
  beforeK1 = currentK1;
  }

  currentK2 = K2R;
  if (currentK2 != beforeK2){
    if (currentK2 == LOW){
      Serial.print("TOK2D\r");
    } else {
      Serial.print("TOK2U\r");
    }
  beforeK2 = currentK2;
  }

  currentK3 = K3R;
  if (currentK3 != beforeK3){
    if (currentK3 == LOW){
      Serial.print("TOK3U\r");
    } else {
      Serial.print("TOK3D\r");
    }
  beforeK3 = currentK3;
  }

  currentK4 = K4R;
  if (currentK4 != beforeK4){
    if (currentK4 == LOW){
      Serial.print("TOK4D\r");
    } else {
      Serial.print("TOK4U\r");
    }
  beforeK4 = currentK4;
  }

  currentK6 = K6R;
  if (currentK6 != beforeK6){
    if (currentK6 == LOW){
      Serial.print("TOK6D\r");
    } else {
      Serial.print("TOK6U\r");
    }
  beforeK6 = currentK6;
  }

  if (FWDR == LOW){
    currentR = 3;
  } if (BCKR == LOW){
    currentR = 1;
  } else {
    currentR = 2;
  }
  if (currentR != beforeR){
    if (currentR == 3){
      Serial.print("TORF\r");
    }
    if (currentR == 2){
      Serial.print("TORN\r");
    }
    if (currentR == 1){
      Serial.print("TORR\r");
    }
  beforeR = currentR;
  }

}


>Back to prev
>Back to index

Sponsored by Google Adsense