Prvni ulozeni z chegewara githubu
This commit is contained in:
46
libraries/ESP32/examples/Touch/TouchButton/TouchButton.ino
Normal file
46
libraries/ESP32/examples/Touch/TouchButton/TouchButton.ino
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
|
||||
This is an example how to use Touch Intrrerupts
|
||||
The sketh will tell when it is touched and then relesased as like a push-button
|
||||
|
||||
This method based on touchInterruptSetThresholdDirection() is only available for ESP32
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
int threshold = 40;
|
||||
bool touchActive = false;
|
||||
bool lastTouchActive = false;
|
||||
bool testingLower = true;
|
||||
|
||||
void gotTouchEvent(){
|
||||
if (lastTouchActive != testingLower) {
|
||||
touchActive = !touchActive;
|
||||
testingLower = !testingLower;
|
||||
// Touch ISR will be inverted: Lower <--> Higher than the Threshold after ISR event is noticed
|
||||
touchInterruptSetThresholdDirection(testingLower);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(1000); // give me time to bring up serial monitor
|
||||
Serial.println("ESP32 Touch Interrupt Test");
|
||||
touchAttachInterrupt(T2, gotTouchEvent, threshold);
|
||||
|
||||
// Touch ISR will be activated when touchRead is lower than the Threshold
|
||||
touchInterruptSetThresholdDirection(testingLower);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
if(lastTouchActive != touchActive){
|
||||
lastTouchActive = touchActive;
|
||||
if (touchActive) {
|
||||
Serial.println(" ---- Touch was Pressed");
|
||||
} else {
|
||||
Serial.println(" ---- Touch was Released");
|
||||
}
|
||||
}
|
||||
Serial.printf("T2 pin2 = %d \n", touchRead(T2));
|
||||
delay(125);
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
|
||||
This is an example how to use Touch Intrrerupts
|
||||
The sketh will tell when it is touched and then relesased as like a push-button
|
||||
|
||||
This method based on touchInterruptGetLastStatus() is only available for ESP32 S2 and S3
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
int threshold = 1500; // ESP32S2
|
||||
bool touch1detected = false;
|
||||
bool touch2detected = false;
|
||||
|
||||
void gotTouch1() {
|
||||
touch1detected = true;
|
||||
}
|
||||
|
||||
void gotTouch2() {
|
||||
touch2detected = true;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(1000); // give me time to bring up serial monitor
|
||||
|
||||
Serial.println("\n ESP32 Touch Interrupt Test\n");
|
||||
touchAttachInterrupt(T1, gotTouch1, threshold);
|
||||
touchAttachInterrupt(T2, gotTouch2, threshold);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (touch1detected) {
|
||||
touch1detected = false;
|
||||
if (touchInterruptGetLastStatus(T1)) {
|
||||
Serial.println(" --- T1 Touched");
|
||||
} else {
|
||||
Serial.println(" --- T1 Released");
|
||||
}
|
||||
}
|
||||
if (touch2detected) {
|
||||
touch2detected = false;
|
||||
if (touchInterruptGetLastStatus(T2)) {
|
||||
Serial.println(" --- T2 Touched");
|
||||
} else {
|
||||
Serial.println(" --- T2 Released");
|
||||
}
|
||||
}
|
||||
|
||||
delay(80);
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
This is an example how to use Touch Intrrerupts
|
||||
The bigger the threshold, the more sensible is the touch
|
||||
*/
|
||||
|
||||
int threshold = 40;
|
||||
bool touch1detected = false;
|
||||
bool touch2detected = false;
|
||||
|
||||
void gotTouch1(){
|
||||
touch1detected = true;
|
||||
}
|
||||
|
||||
void gotTouch2(){
|
||||
touch2detected = true;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(1000); // give me time to bring up serial monitor
|
||||
Serial.println("ESP32 Touch Interrupt Test");
|
||||
touchAttachInterrupt(T2, gotTouch1, threshold);
|
||||
touchAttachInterrupt(T3, gotTouch2, threshold);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
if(touch1detected){
|
||||
touch1detected = false;
|
||||
Serial.println("Touch 1 detected");
|
||||
}
|
||||
if(touch2detected){
|
||||
touch2detected = false;
|
||||
Serial.println("Touch 2 detected");
|
||||
}
|
||||
}
|
15
libraries/ESP32/examples/Touch/TouchRead/TouchRead.ino
Normal file
15
libraries/ESP32/examples/Touch/TouchRead/TouchRead.ino
Normal file
@ -0,0 +1,15 @@
|
||||
// ESP32 Touch Test
|
||||
// Just test touch pin - Touch0 is T0 which is on GPIO 4.
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000); // give me time to bring up serial monitor
|
||||
Serial.println("ESP32 Touch Test");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println(touchRead(T1)); // get value using T0
|
||||
delay(1000);
|
||||
}
|
Reference in New Issue
Block a user