1
1

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でアナログジョイスティックの上限を求めて遊ぶ(少し改良)

Last updated at Posted at 2025-02-09

x 過去ログを見て!!!

結果

Screenshot from 2025-02-10 06-29-36.jpg

image_original (44).jpg

プログラム





//ser_analog_joystick_max_M5StampS3

#define G_X 13
#define G_Y 15

void setup() {
  // put your setup code here, to run once:

  //シリアルの初期化
  Serial.begin(9600);
  Serial.println();
  //シリアルの待ちが0.5*9
  for (int i = 0; i < 9; i++) {
    Serial.print('.');delay(500);  //接続待ち
  } //for
  Serial.println();

  pinMode(G_X, ANALOG);  //gpio init
  pinMode(G_Y, ANALOG);  //gpio init

  float c_yl = 0;
  float c_yr = 0;

  int s = 0;  //input
  for (int i = 0; i < 128; i++) {
    //センサー入力する
    s = s + analogRead(G_X);             //センサーの値
  } //for
  s = s >> 7;                            // s / 128
  c_yl = ((float)s) * (3.3f / 4096.0f);  //  電圧こと

  s = 0;
  for (int i = 0; i < 128; i++) {
    //センサー入力する
    s = s + analogRead(G_Y);             //センサーの値
  } //for
  s = s >> 7;                            // s / 128
  c_yr = ((float)s) * (3.3f / 4096.0f);  //  電圧こと

  //表示
  Serial.print(c_yl);
  Serial.print(',');
  Serial.print(c_yr);
  Serial.println();

} //setup

void loop() {
  // put your main code here, to run repeatedly:

  delay(300);  //ダミー 0.3秒待つ

} //loop




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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?