Code Monkey home page Code Monkey logo

Comments (9)

HomeSpan avatar HomeSpan commented on July 30, 2024

Sorry, but the Touch Sensor library on the ESP32 is quite complicated and the button class would need to be significantly changed to incorporate that library.

from homespan.

pcossutta avatar pcossutta commented on July 30, 2024

@PeteBurgess to use touch in the Arduino IDE is as easy as do a comparison: touchRead(13) < TOUCH_LMT. TOUCH_LMT depends on the surface used as sensor, but you could easily print touchRead values and calibrate from there. Of course you need everything related to a button after that. such as debounce. Hope it helps.

Code sample:

int lastState = LOW;
int lastDebouncedState = LOW;
int currentState;
unsigned long lastDebounceTime = 0;
#define TOUCH_LMT 35
#define DEBOUNCE_DELAY 50

void setup() {
}

void loop(){ 
  currentState = touchRead(13) < TOUCH_LMT;
  // If the switch/button changed, due to noise or pressing:
  if (currentState != lastState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
    // save the the last flickerable state
    lastState = currentState;
  }
  if ((millis() - lastDebounceTime) > DEBOUNCE_DELAY) {
    if(lastDebouncedState == HIGH && currentState == LOW) 
      Serial.println("Button pressed");
    else if(lastDebouncedState == LOW && currentState == HIGH)
      Serial.println("Button released");
    lastDebouncedState = currentState;
}     

from homespan.

HomeSpan avatar HomeSpan commented on July 30, 2024

Wow - thank you! I had no idea the ESP32-Arduino library had this feature. This makes it a LOT easier to integrate. I will extend the button class to allow the use of touchRead. Probably won't be able to get it into the next update (which I'm hoping to release later this week) but should be able to add it to the next one (as well as provide it earlier in dev once ready).

from homespan.

PeteBurgess avatar PeteBurgess commented on July 30, 2024

Thanks. I’ve used it before, it actually works pretty well.

from homespan.

guigoruiz1 avatar guigoruiz1 commented on July 30, 2024

Hello, has this been implemented?

from homespan.

HomeSpan avatar HomeSpan commented on July 30, 2024

Sorry, I have not yet added that to HomeSpan, but hope to in a future release. Given other similar requests for alternative buttons (pull-ups, use of multiplexers, etc.) I anticipate making something more generic so that the user can define a function that simply returns true/false depending on whether the "button" is pressed, regardless of button type.

Note you can still use the touch library at present with HomeSpan, but you will need to add logic to process the "touches" in the loop() method of a Service, instead of using SpanButton

from homespan.

HomeSpan avatar HomeSpan commented on July 30, 2024

HomeSpan version 1.6.0 (just released) now includes the ability to use touch pad/sensors with SpanButton. Complete details can be found in the the latest version of SpanButton() in the API documentation, with additional tutorial instructions describing how touch pad sensitivity is calibrated added to the end of Example 15 - RealPushButtons. Thanks for raising this request!

from homespan.

guigoruiz1 avatar guigoruiz1 commented on July 30, 2024

Is it possible to use the touch sensor as control pin?

from homespan.

HomeSpan avatar HomeSpan commented on July 30, 2024

No, you can only use touch for SpanButton at this time. Control still needs to be a physical button to ground.

from homespan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.