ESP32には10本ものタッチセンサーがあります。しかも、インタラプト関数が用意されているので便利に使えそうです。

ESP32の安価でコンパクトなボードを購入したので試しに使ってみようと思います。特にアフィリエイトが得られるわけではありませんが、購入先は下記URLです。
https://ja.aliexpress.com/item/MH-ET-LIVE-D1-mini-ESP32-ESP-32-WiFi-Bluetooth-Internet-of-Things-development-board-based/32816658883.html?spm=a2g0s.9042311.0.0.u50SMy
このボードはLチカ用LEDが付いているのが原因だと思いますが、T2は使えません。また、T8とT9が入れ替わっているようです。
T0–IO04
T1–IO0
T3–TDO
T4–TCK
T5–TDI
T6–TMS
T7–IO27
T8–IO32
T9–IO33
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
int threshold[9] = {12,12,12,12,12,12,12,12,12,}; bool touchDetected[9] ={false,false,false,false,false,false,false,false,false}; int T[9]={T0,T1,T3,T4,T5,T6,T7,T9,T8}; void gotTouch0(){ touchDetected[0] = true; } void gotTouch1(){ touchDetected[1] = true; } void gotTouch2(){ touchDetected[2] = true; } void gotTouch3(){ touchDetected[3] = true; } void gotTouch4(){ touchDetected[4] = true; } void gotTouch5(){ touchDetected[5] = true; } void gotTouch6(){ touchDetected[6] = true; } void gotTouch7(){ touchDetected[7] = true; } void gotTouch8(){ touchDetected[8] = true; } void setup() { Serial.begin(115200); delay(1000); // give me time to bring up serial monitor Serial.println("TouchInterrupt9"); touchAttachInterrupt(T[0], gotTouch0, threshold[0]); touchAttachInterrupt(T[1], gotTouch1, threshold[1]); touchAttachInterrupt(T[2], gotTouch2, threshold[2]); touchAttachInterrupt(T[3], gotTouch3, threshold[3]); touchAttachInterrupt(T[4], gotTouch4, threshold[4]); touchAttachInterrupt(T[5], gotTouch5, threshold[5]); touchAttachInterrupt(T[6], gotTouch6, threshold[6]); touchAttachInterrupt(T[7], gotTouch7, threshold[7]); touchAttachInterrupt(T[8], gotTouch8, threshold[8]); } void loop(){ int value; for(int i=0;i<9;i++){ if(touchDetected[i] && ((value=touchRead(T[i]))<threshold[i])){ touchDetected[i]=false; Serial.print(i);Serial.print(" detected with"); Serial.println(value); } } } |
フラットケーブルを使ったら60ぐらいあったタッチセンサーの出力が20ぐらいまで低下して、検知できるギリギリですがなんとか使えています。
(18.02.11)