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

More than 5 years have passed since last update.

ESP32でタッチセンサ

Last updated at Posted at 2019-11-28

3ボタンのタッチセンサをさくっと作ってみます。

ESP32のタッチセンサ機能は以下のように割り当てられているみたいです。

  • T0 GPIO4
  • T1 GPIO0
  • T2 GPIO2
  • T3 GPIO15
  • T4 GPIO13
  • T5 GPIO12
  • T6 GPIO14
  • T7 GPIO27
  • T8 GPIO33
  • T9 GPIO32

このうちの、GPIO12,13,14ピンに接続したパッドをタッチセンサにします。

絶対値は使用環境によってゆらぎが入るので、3ボタンの平均値を求め、その平均値に係数をかけたものをしきい値としてボタンにタッチしたかどうかを判定するようにしました。

void setup()
{
  Serial.begin(115200);
  delay(1000);
  Serial.println("Touch Sensor Test");
}

void loop()
{
  int v0,v1,v2,vborder;
  v0 = touchRead(T4);
  v1 = touchRead(T5);
  v2 = touchRead(T6);
  float coefficient=0.3;
  vborder=(v0+v1+v2)/3*coefficient;
  if (v0 < vborder ) {
    Serial.print(" ON  ");
  } else {
    Serial.print(" OFF ");
  }
  if (v1 < vborder ) {
    Serial.print(" ON  ");
  } else {
    Serial.print(" OFF ");
  }
  if (v2 < vborder ) {
    Serial.print(" ON  ");
  } else {
    Serial.print(" OFF ");
  }
  Serial.println();
  delay(100);
}

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