1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

M5StampS3をUSBキーボードにして遊ぶ。

Last updated at Posted at 2025-09-25

参考

いろいろ注意

  • 過去ログを見ょ!!!
  • いろいろ、なんか、いろいろ、食いついて来たが?
  • いろいろ、作れそうだから、作る
  • いろいろ、動きそうだから、動かす
  • いろいろ、軽いノリで作っている?
  • いろいろ、キーボードのはなしは、重いんだ?(なんの事?(入力コントローラーと同じ、匂いがする?
  • 再書き込みは、オートブートでUSBシリアルが使えなくなるので、ボタンを使ってブートして、書き込みモードにする
  • 変更点

const int buttonPin = 15;

結果

Screenshot from 2025-09-26 06-24-15.png

Screenshot from 2025-09-26 06-23-03.png

image_original(80).jpg

プログラム


#include "USB.h"
#include "USBHIDKeyboard.h"
USBHIDKeyboard Keyboard;

const int buttonPin = 15;
int previousButtonState = HIGH;
int counter = 0;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
  Keyboard.begin();
  USB.begin();
}

void loop() {
  int buttonState = digitalRead(buttonPin);
  if ((buttonState != previousButtonState) && (buttonState == LOW)) {
    counter++;
    Keyboard.print("You pressed the button ");
    Keyboard.print(counter);
    Keyboard.println(" times.");
  }
  previousButtonState = buttonState;
  delay(1);
}


1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?