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でアナログジョイスティックのセンターを求める

Last updated at Posted at 2025-01-29

x 過去ログを見よ!!!
x 自動整形をわすれた(めんどいのでそのまま)
x 3.1.1

いろいろ
M5StampS3が物凄い勢いで無くなっているが、なんかあるんか?(20250130)
有線(有線は、ラジコンとは、言わない)で制御するのがやっぱり多いな
いきなり、ラジコンは、飛ばしすぎ!!!(ももクロの歌みたい(なんのこと))
(有線は、まにゅびれーた?)

目的
電圧を100回計って平均を求める

結果

Screenshot from 2025-01-30 05-09-49_original.jpg

image_original (39).jpg

プログラム


//ser_analog_joystick_c_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++) {
    delay(500);  //接続待ち
    Serial.print(".");
  }  //for
  Serial.println("");

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

  float c_yl=0;
  float c_yr=0;

  float s; //input

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

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

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

}

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

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

}


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?