1.ユニバーサル基板の実装図
取扱いの利便性を考え、Arduino Pro Micro及び各スイッチ類への接続はQIコネクタを通して行います。よって基板上にはコネクタと分圧抵抗用回路用お抵抗しか載っていません。表面 |
・2,3,GNDのコネクタ
TS3A(ON-OFF-ONトグル)
・4,5,GNDのコネクタ
TS3B(ON-OFF-ONトグル)
・6,7,GNDのコネクタ
TS3C(ON-OFF-ONトグル)
・8,GNDのコネクタ
TS2A(ON-OFFトグル)
・9,GNDのコネクタ
TS2B(ON-OFFトグル)
・10,Vcc.GNDの5PINコネクタ
RS4A(4ポジションロータリスイッチ)
・16,GNDのコネクタ
PBA(リセット用プッシュボタン)
・14,15,GNDのコネクタ
RS3A(3ポジションロータリスイッチ)
・A0,A1,GNDのコネクタ
RS3B(3ポジションロータリスイッチ)
裏面 |
VOLA(アナログボリューム)
・A3,Vcc,GNDのコネクタ
VOLB(アナログボリューム)
デバイス名対応表 |
2.スイッチ類の配線処理
スイッチ類ヘはリード線をはんだ付けし、収縮チューブで保護。なんとなくフラットケーブル状になる様にして仕舞い易くしています。基板側にはQIコネクタのオスを加締め。2ピン、3ピン等のソケットを使い分けるとより便利。3.コーディング
その3で動作確認したコードを組み合わせてコーディングします。関数化とかしてませんが、許してください。#include "Joystick.h"
//シリアルモニタ出力 mon = 1 出力オン/ mon = 0 出力オフ
int mon = 0;
int P1 = 0;
int P2 = 0;
int i = 0;
//アナログ軸数値の初期化
int VOLAValue = 0;
int currentVOLAValue = 0;
int VOLBValue = 0;
int currentVOLBValue = 0;
//仮想ボタンの初期化
int TS3APosition = 0;
int currentTS3APosition = 0;
int PIN2State = 0;
int PIN3State = 0;
int TS3BPosition = 0;
int currentTS3BPosition = 0;
int PIN4State = 0;
int PIN5State = 0;
int TS3CPosition = 0;
int currentTS3CPosition = 0;
int PIN6State = 0;
int PIN7State = 0;
int TS2APosition = 0;
int currentTS2APosition = 0;
int PIN8State = 0;
int TS2BPosition = 0;
int currentTS2BPosition = 0;
int PIN9State = 0;
int RS3APosition = 0;
int currentRS3APosition = 0;
int PINA1State = 0;
int PINA0State = 0;
int RS3BPosition = 0;
int currentRS3BPosition =0;
int PIN15State = 0;
int PIN14State = 0;
int PBAState = 0;
int currentPBAState = 0;
int RS4APosition = 0;
int currentRS4APosition = 0;
int RS4AValue = 0;
//ジョイスティックの開始
Joystick_ Joystick;
void setup() {
//シリアルモニタ開始
Serial.begin(9600);
//ジョイスティックの初期化
Joystick.begin();
//デジタルピン設定
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
pinMode(A2, INPUT_PULLUP);
pinMode(15, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
pinMode(16, INPUT_PULLUP);
}
void loop() {
//-----------------------------------------------------TS3Aの処理-------------------------------------------------------
//TS3Aの処理
PIN2State = !digitalRead(2);
PIN3State = !digitalRead(3);
if(PIN2State == HIGH){
currentTS3APosition = 0;
} else if (PIN3State == HIGH){
currentTS3APosition = 2;
} else {
currentTS3APosition = 1;
}
if ( currentTS3APosition != TS3APosition){
for (i=0 ; i<=2 ; i++){
Joystick.setButton(i,LOW);
}
Joystick.setButton(currentTS3APosition,HIGH);
if (mon == 3){
Serial.print("Position ");
Serial.print(TS3APosition);
Serial.print(" to ");
Serial.println(currentTS3APosition);
}
TS3APosition = currentTS3APosition;
}
//-----------------------------------------------------TS3Bの処理-------------------------------------------------------
//TS3Bの処理
PIN4State = !digitalRead(4);
PIN5State = !digitalRead(5);
if(PIN4State == HIGH){
currentTS3BPosition = 3;
} else if (PIN5State == HIGH){
currentTS3BPosition = 5;
} else {
currentTS3BPosition = 4;
}
if ( currentTS3BPosition != TS3BPosition){
for (i=3 ; i<=5 ; i++){
Joystick.setButton(i,LOW);
}
Joystick.setButton(currentTS3BPosition,HIGH);
if (mon == 3){
Serial.print("Position ");
Serial.print(TS3BPosition);
Serial.print(" to ");
Serial.println(currentTS3BPosition);
}
TS3BPosition = currentTS3BPosition;
}
//-----------------------------------------------------TS3Cの処理-------------------------------------------------------
//TS3Cの処理
PIN6State = !digitalRead(6);
PIN7State = !digitalRead(7);
if(PIN6State == HIGH){
currentTS3CPosition = 6;
} else if (PIN7State == HIGH){
currentTS3CPosition = 8;
} else {
currentTS3CPosition = 7;
}
if ( currentTS3CPosition != TS3CPosition){
for (i=6 ; i<=8 ; i++){
Joystick.setButton(i,LOW);
}
Joystick.setButton(currentTS3CPosition,HIGH);
if (mon == 3){
Serial.print("Position ");
Serial.print(TS3CPosition);
Serial.print(" to ");
Serial.println(currentTS3CPosition);
}
TS3CPosition = currentTS3CPosition;
}
//-----------------------------------------------------TS2Aの処理-------------------------------------------------------
//TS2Aの処理
PIN8State = !digitalRead(8);
if(PIN8State == HIGH){
currentTS2APosition = 10;
} else {
currentTS2APosition = 9;
}
if ( currentTS2APosition != TS2APosition){
for (i=9 ; i<=10 ; i++){
Joystick.setButton(i,LOW);
}
Joystick.setButton(currentTS2APosition,HIGH);
if (mon == 3){
Serial.print("Position ");
Serial.print(TS2APosition);
Serial.print(" to ");
Serial.println(currentTS2APosition);
}
TS2APosition = currentTS2APosition;
}
//-----------------------------------------------------TS2Bの処理-------------------------------------------------------
//TS2Bの処理
PIN9State = !digitalRead(9);
if(PIN9State == HIGH){
currentTS2BPosition = 12;
} else {
currentTS2BPosition = 11;
}
if ( currentTS2BPosition != TS2BPosition){
for (i=11 ; i<=12 ; i++){
Joystick.setButton(i,LOW);
}
Joystick.setButton(currentTS2BPosition,HIGH);
if (mon == 3){
Serial.print("Position ");
Serial.print(TS2BPosition);
Serial.print(" to ");
Serial.println(currentTS2BPosition);
}
TS2BPosition = currentTS2BPosition;
}
//-----------------------------------------------------VOLAの処理-------------------------------------------------------
//VOLAの処理
currentVOLAValue = 1023 - analogRead(A3);
if (currentVOLAValue < VOLAValue - 1 || currentVOLAValue > VOLAValue + 1){
if (mon == 1){
Serial.print("VOLA = ");
Serial.println(currentVOLAValue);
}
Joystick.setXAxis(currentVOLAValue);
VOLAValue = currentVOLAValue;
}
//VOLBの処理
currentVOLBValue = 1023 - analogRead(A2);
currentVOLBValue = currentVOLBValue * 1.014;
if (currentVOLBValue < VOLBValue - 1 || currentVOLBValue > VOLBValue + 1){
if (mon == 1){
Serial.print("VOLB = ");
Serial.println(currentVOLBValue);
}
Joystick.setYAxis(currentVOLBValue);
VOLBValue = currentVOLBValue;
}
//-----------------------------------------------------RS3Aの処理-------------------------------------------------------
//RS3Aの処理
PINA1State = !digitalRead(A1);
PINA0State = !digitalRead(A0);
if(PINA1State == HIGH){
currentRS3APosition = 13;
} else if (PINA0State == HIGH){
currentRS3APosition = 15;
} else {
currentRS3APosition = 14;
}
if ( currentRS3APosition != RS3APosition){
for (i=13 ; i<=15 ; i++){
Joystick.setButton(i,LOW);
}
Joystick.setButton(currentRS3APosition,HIGH);
if (mon == 2){
Serial.print("Position ");
Serial.print(RS3APosition);
Serial.print(" to ");
Serial.println(currentRS3APosition);
}
RS3APosition = currentRS3APosition;
}
//-----------------------------------------------------RS3Bの処理-------------------------------------------------------
//RS3Bの処理
PIN15State = !digitalRead(15);
PIN14State = !digitalRead(14);
if(PIN15State == HIGH){
currentRS3BPosition = 16;
} else if (PIN14State == HIGH){
currentRS3BPosition = 18;
} else {
currentRS3BPosition = 17;
}
if ( currentRS3BPosition != RS3BPosition){
for (i=16 ; i<=18 ; i++){
Joystick.setButton(i,LOW);
}
Joystick.setButton(currentRS3BPosition,HIGH);
if (mon == 2){
Serial.print("Position ");
Serial.print(RS3BPosition);
Serial.print(" to ");
Serial.println(currentRS3BPosition);
}
RS3BPosition = currentRS3BPosition;
}
//-----------------------------------------------------PBAの処理-------------------------------------------------------
currentPBAState = digitalRead(16);
if (currentPBAState != PBAState){
if (currentPBAState == LOW){
// Joystick.sendState();
Serial.println("reset!");
}
}
PBAState = currentPBAState;
//-----------------------------------------------------RS4Aのanalog処理-----------------------------------------------------
//anarog値読み取り
RS4AValue = analogRead(10);
if( RS4AValue >=0 && RS4AValue <= 80 ){
P1 = 23;
}
if( RS4AValue > 160 && RS4AValue <= 330){
P1 = 22;
}
if( RS4AValue > 400 && RS4AValue <= 590){
P1 = 21;
}
if( RS4AValue > 650 && RS4AValue <= 850){
P1 = 20;
}
if (P1 != P2) {
P2 = P1;
delay(50);
} else {
currentRS4APosition = P2;
}
if (currentRS4APosition != RS4APosition){
for (i=20 ; i<=23 ; i++){
Joystick.setButton(i,LOW);
}
Joystick.setButton(currentRS4APosition,HIGH);
if (mon == 1){
Serial.print("Position ");
Serial.print(RS4APosition);
Serial.print(" to ");
Serial.println(currentRS4APosition);
}
RS4APosition = currentRS4APosition;
}
delay(50);
}
0 件のコメント:
コメントを投稿