ゲームに使う専用のコントローラーを作りたい


https://www.nextpng.com/en/transparent-png-nbtvo
(画像はArduino UNOですが、この通り配線してください。)


プルアップ回路を自分で作る

管理人
前回のプログラム↓の赤字部分を削除
- #include <Keyboard.h>
- void setup() {
- // make pin 2 an input and turn on the
- // pullup resistor so it goes high unless
- // connected to ground:
- pinMode(2, INPUT_PULLUP);
- Keyboard.begin();
- }
- void loop() {
- //if the button is pressed
- if (digitalRead(2) == LOW) {
- //Send an ASCII 'A',
- Keyboard.write(65);
- delay(200);
- }
- }
以下の画像のように配線

https://www.nextpng.com/en/transparent-png-nbtvo
(画像はArduino UNOですが、この通り配線してください。)

管理人
これでプルアップ回路が作成できました。
ボタンを押せばAが入力されると思います。
ボタンを増やす

- #include <Keyboard.h>
- void setup() {
- pinMode(2, INPUT);
- pinMode(4, INPUT);
- Keyboard.begin();
- }
- void loop() {
- if (digitalRead(2) == LOW) {
- Keyboard.write(65);
- delay(200);
- }
- if (digitalRead(4) == LOW) {
- Keyboard.write(66);
- delay(200);
- }
- }

管理人
単純に増やすだけなので非常に簡単ですね。
次はキーボードの関数についてです。