TouchPiny nie są dostępne wariantach C3. Warto dodać kondensator 100nF między pinem a GND – stabilizuje odczyty.
Domyślnie wartość pinu wynosi 125, a wraz z siłą docisku wartość spada.
Numer GPIO Numer Touch
GPIO 4 T0
GPIO 0 T1
GPIO 2 T2
GPIO 15 T3
GPIO 13 T4
GPIO 12 T5
GPIO 14 T6
GPIO 27 T7
GPIO 33 T8
GPIO 32 T9
Odczytywanie wartości docisku pinu na ESP32
const int touchPin = T2;
void setup() {
Serial.begin(115200);
}
void loop() {
int touchValue = touchRead(touchPin);
Serial.printf("Wartość dotyku: %d\n", touchValue);
delay(500);
}
Touchpin jako przycisk ESP32
const int touchPin = T2;
const int threshold = 30;
void setup() {
Serial.begin(115200);
}
void loop() {
int touchValue = touchRead(touchPin);
if (touchValue < threshold) {
Serial.println("Dotknięto!");
}
delay(200);
}
Wyświetlanie wartości touch na OLED
#include <TFT_eSPI.h>
#include <Arduino.h>
TFT_eSPI tft = TFT_eSPI();
const int touchPin = T2;
void setup() {
Serial.begin(115200);
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.setTextSize(4);
}
void loop() {
int touchValue = touchRead(touchPin);
tft.fillScreen(TFT_BLACK);
tft.setCursor(10, 20);
tft.print(touchValue);
delay(500);
}