toyking
조이스틱 Joystick 만들기 (마메용, 아두이노) 본문
종이상자에 탁상달력의 두툼한 종이부분을 덧붙여서 만들어봄
상판이 눌릴까 싶어 종이기둥을 만들어 줌 | 버튼 3개만 연결 (아두이노 소스코딩은 6개) |
아두이노 레오나르도 핀 번호와 키보드값 설정 (스위치를 달아서 1 player , 2 player 선택할 수 있게 설정)
스위치 | 6 | 6 핀 off (1 player) | 6 핀 on (2 player) |
핀 번호 | 키보드 값 | ||
레버 | 0 | KEY_UP_ARROW | 232 (키패드 8) |
1 | KEY_DOWN_ARROW | 229 (키패드 5) | |
2 | KEY_RIGHT_ARROW | 230 (키패드 6) | |
3 | KEY_LEFT_ARROW | 228 (키패드 4) | |
버튼키 | A0 | a | g |
A1 | s | h | |
A2 | d | j | |
A3 | q | t | |
A4 | w | y | |
A5 | e | u | |
시작 , 코인 | 4 | 1 | 2 |
5 | 5 | 6 | |
기능키 | 7 | KEY_TAB | |
8 | KEY_ESC | ||
9 | p | ||
10 | KEY_RETURN | ||
11 | |||
12 | z | ||
13 | x |
회색 색상은 연결 안한 부분임. 버튼추가시 연결.
아두이노 레오나르도 소스코드
//2020.06.19 keyjoystick2p7zx 용 작성
// 6번 핀의 연결 유,무 에 따라서 1player 2player 전환. 기능키 설정.
#define DELAY 1 // Delay per loop in ms
#include <Keyboard.h>
void setup() {
// put your setup code here, to run once:
// 1p 레버 , 2p 레버
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
// 1p 버튼 , 2p 버튼
pinMode(A0, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
pinMode(A2, INPUT_PULLUP);
pinMode(A3, INPUT_PULLUP);
pinMode(A4, INPUT_PULLUP);
pinMode(A5, 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(10, INPUT_PULLUP);
//
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(13, INPUT_PULLUP);
Keyboard.begin();
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
// 6번 핀의 연결 유,무 에 따른 조건문 1,2player 선택
// 6번 핀이 off시 조건문 시작 1player - 방향키 : 화살표 . 버튼: a s d q w e 5 1 //
if(digitalRead(6)==HIGH){
// 1p 레버
if(digitalRead(0)==LOW){
Keyboard.press(KEY_UP_ARROW);
}
if(digitalRead(0)==HIGH){
Keyboard.release(KEY_UP_ARROW);
}
if(digitalRead(1)==LOW){
Keyboard.press(KEY_DOWN_ARROW);
}
if(digitalRead(1)==HIGH){
Keyboard.release(KEY_DOWN_ARROW);
}
if(digitalRead(2)==LOW){
Keyboard.press(KEY_RIGHT_ARROW);
}
if(digitalRead(2)==HIGH){
Keyboard.release(KEY_RIGHT_ARROW);
}
if(digitalRead(3)==LOW){
Keyboard.press(KEY_LEFT_ARROW);
}
if(digitalRead(3)==HIGH){
Keyboard.release(KEY_LEFT_ARROW);
}
// 1p 버튼
if(digitalRead(A0)==HIGH){
Keyboard.release('a');
}
if(digitalRead(A0)==LOW){
Keyboard.press('a');
}
if(digitalRead(A1)==HIGH){
Keyboard.release('s');
}
if(digitalRead(A1)==LOW){
Keyboard.press('s');
}
if(digitalRead(A2)==HIGH){
Keyboard.release('d');
}
if(digitalRead(A2)==LOW){
Keyboard.press('d');
}
if(digitalRead(A3)==HIGH){
Keyboard.release('q');
}
if(digitalRead(A3)==LOW){
Keyboard.press('q');
}
if(digitalRead(A4)==HIGH){
Keyboard.release('w');
}
if(digitalRead(A4)==LOW){
Keyboard.press('w');
}
if(digitalRead(A5)==HIGH){
Keyboard.release('e');
}
if(digitalRead(A5)==LOW){
Keyboard.press('e');
}
// 1p 버튼 기능키 start : 1 . coin : 5
if(digitalRead(4)==HIGH){
Keyboard.release('1');
}
if(digitalRead(4)==LOW){
Keyboard.press('1');
}
if(digitalRead(5)==HIGH){
Keyboard.release('5');
}
if(digitalRead(5)==LOW){
Keyboard.press('5');
}
} // 6번 핀이 off시 조건문 닫기 ///////////////////////////////////////////
// 6번 핀이 on시 조건문 시작 2player - 방향키 : Num 8 5 6 4 . 버튼 : g h j t y u 6 2 //
else {
// 2p 레버
if(digitalRead(0)==LOW){
Keyboard.press(232);
}
if(digitalRead(0)==HIGH){
Keyboard.release(232);
}
if(digitalRead(1)==LOW){
Keyboard.press(229);
}
if(digitalRead(1)==HIGH){
Keyboard.release(229);
}
if(digitalRead(2)==LOW){
Keyboard.press(230);
}
if(digitalRead(2)==HIGH){
Keyboard.release(230);
}
if(digitalRead(3)==LOW){
Keyboard.press(228);
}
if(digitalRead(3)==HIGH){
Keyboard.release(228);
}
// 2p 버튼
if(digitalRead(A0)==HIGH){
Keyboard.release('g');
}
if(digitalRead(A0)==LOW){
Keyboard.press('g');
}
if(digitalRead(A1)==HIGH){
Keyboard.release('h');
}
if(digitalRead(A1)==LOW){
Keyboard.press('h');
}
if(digitalRead(A2)==HIGH){
Keyboard.release('j');
}
if(digitalRead(A2)==LOW){
Keyboard.press('j');
}
if(digitalRead(A3)==HIGH){
Keyboard.release('t');
}
if(digitalRead(A3)==LOW){
Keyboard.press('t');
}
if(digitalRead(A4)==HIGH){
Keyboard.release('y');
}
if(digitalRead(A4)==LOW){
Keyboard.press('y');
}
if(digitalRead(A5)==HIGH){
Keyboard.release('u');
}
if(digitalRead(A5)==LOW){
Keyboard.press('u');
}
// 2p 버튼 기능키 start : 2 . coin : 6
if(digitalRead(4)==HIGH){
Keyboard.release('2');
}
if(digitalRead(4)==LOW){
Keyboard.press('2');
}
if(digitalRead(5)==HIGH){
Keyboard.release('6');
}
if(digitalRead(5)==LOW){
Keyboard.press('6');
}
} // 6번 핀이 on시 조건문 닫기 ///////////////////
//////////////////////////////////////////////////////////
// 기능키
if(digitalRead(7)==HIGH){
Keyboard.release(KEY_TAB);
}
if(digitalRead(7)==LOW){
Keyboard.press(KEY_TAB);
}
if(digitalRead(8)==HIGH){
Keyboard.release(KEY_ESC);
}
if(digitalRead(8)==LOW){
Keyboard.press(KEY_ESC);
}
if(digitalRead(9)==HIGH){
Keyboard.release('p');
}
if(digitalRead(9)==LOW){
Keyboard.press('p');
}
if(digitalRead(10)==HIGH){
Keyboard.release(KEY_RETURN);
}
if(digitalRead(10)==LOW){
Keyboard.press(KEY_RETURN);
}
if(digitalRead(12)==HIGH){
Keyboard.release('z');
}
if(digitalRead(12)==LOW){
Keyboard.press('z');
}
if(digitalRead(13)==HIGH){
Keyboard.release('x');
}
if(digitalRead(13)==LOW){
Keyboard.press('x');
}
delay(DELAY);
} // void loop() 닫기
'Computer > Tip' 카테고리의 다른 글
Num Lock (숫자 키패드) 부팅시 자동 켜기 (0) | 2024.08.20 |
---|---|
메인보드 백패널(I/O) 만들기 (0) | 2024.08.16 |
노트북 부품(웹카메라) 활용 (1) | 2020.09.22 |
mame120-del (0) | 2020.02.14 |
윈도우 2000 고용량 하드(HDD) 인식 (0) | 2018.09.16 |