In meinem letzten Beitrag habe ich die blaue LED auf dem Board blinken lassen und die grundsätzliche Funktionalität getestet.
Irgendwo bin ich über die Touchfunktion gestolpert: d.h., man berührt einen Kontakt der Chip reagiert darauf. Im folgenden der Code dafür und der Schaltplan.
#define LED 22 int threshold = 40; bool touch1detected = false; bool touch2detected = false; void gotTouch(){ touch1detected = true; } void gotTouch1(){ touch2detected = true; } void setup() { Serial.begin(115200); delay(1000); // give me time to bring up serial monitor pinMode(LED, OUTPUT); printf("\n ESP32 Touch Interrupt Test\n"); touchAttachInterrupt(T2, gotTouch, threshold); // T2 on GPIO2 touchAttachInterrupt(T3, gotTouch1, threshold); //T3 on GPIO15 } void loop(){ if(touch1detected){ touch1detected = false; Serial.println("Touch 1 detected"); digitalWrite(LED,HIGH); } else if(touch2detected){ touch2detected = false; Serial.println("Touch 2 detected"); digitalWrite(LED,HIGH); } else digitalWrite(LED,LOW); delay(1000); }
Berührt man den an Pin 2 oder 15 angeschlossenen Draht, leuchtet die LED.
Schreib als Erster einen Kommentar