Jump to content
43oh

Setting Threshhold for touch buttons?


Recommended Posts

Hello,

 

I have made a led panel control using the M430G2452 chip. I use the standard software as in the Touch examples CapTouchButton software, only with 10 buttons connected, on pin P1_4 to P1_7 and P2_0 to P2_5. Some work perfect, and very stable, but some just give a touch event now and then, random, some very few, some very often. Changing the M430G2452 chip for another one changes the behaviour.

 

Is there a possibility to make this Button touch more stable, like increasing the Threshold. Somehow I cannot read and set this threshold in my software, it only seems to work with proximity bottuns. Any suggestuions are very very welcome. Software below (I know, I am a amateur, I am an electronic engineer, and the electronics side is very good :)

 

-------------------------------------------------------

 

#include <CapTouch.h>

#define ONOFFB P2_2
#define POWER1B P2_3
#define POWER2B P2_4
#define POWER3B P2_1
#define POWER4B P2_5
#define POWER5B P2_0
#define POWER6B P1_6
#define POWER7B P1_5
#define POWER8B P1_7
#define POWER9B P1_4

#define PWMOUT P1_2
#define LEDOUT P1_3

int Function = 0;
int Light = 0;

CapTouch ONOFF = CapTouch(ONOFFB, TOUCH_BUTTON);
CapTouch POWER1 = CapTouch(POWER1B, TOUCH_BUTTON);
CapTouch POWER2 = CapTouch(POWER2B, TOUCH_BUTTON);
CapTouch POWER3 = CapTouch(POWER3B, TOUCH_BUTTON);
CapTouch POWER4 = CapTouch(POWER4B, TOUCH_BUTTON);
CapTouch POWER5 = CapTouch(POWER5B, TOUCH_BUTTON);
CapTouch POWER6 = CapTouch(POWER6B, TOUCH_BUTTON);
CapTouch POWER7 = CapTouch(POWER7B, TOUCH_BUTTON);
CapTouch POWER8 = CapTouch(POWER8B, TOUCH_BUTTON);
CapTouch POWER9 = CapTouch(POWER9B, TOUCH_BUTTON);

void setup() {
  pinMode(PWMOUT, OUTPUT);
  pinMode(LEDOUT, OUTPUT);
}

void loop() {
 
    analogWrite(PWMOUT, 0);
    digitalWrite(LEDOUT, LOW);
    
    do {
      Function = 0;
      
      if (ONOFF.isTouched()){delay(20); if (ONOFF.isTouched()){Function = 1;}}
      if (POWER1.isTouched()){delay(20); if (POWER1.isTouched()){Function = 3;}}
      if (POWER2.isTouched()){delay(20); if (POWER2.isTouched()){Function = 4;}}
      if (POWER3.isTouched()){delay(20); if (POWER3.isTouched()){Function = 5;}}
      if (POWER4.isTouched()){delay(20); if (POWER4.isTouched()){Function = 6;}}
      if (POWER5.isTouched()){delay(20); if (POWER5.isTouched()){Function = 7;}}
      if (POWER6.isTouched()){delay(20); if (POWER6.isTouched()){Function = 8;}}
      if (POWER7.isTouched()){delay(20); if (POWER7.isTouched()){Function = 9;}}
      if (POWER8.isTouched()){delay(20); if (POWER8.isTouched()){Function = 10;}}
      if (POWER9.isTouched()){delay(20); if (POWER9.isTouched()){Function = 11;}}
      
      Light = analogRead(A0);
      if (Light < 400) {digitalWrite(LEDOUT, LOW);}
      if (Light > 600) {digitalWrite(LEDOUT, HIGH);}

      if (Function != 0) {
        digitalWrite(PWMOUT, HIGH);
        delay(1);
        digitalWrite(PWMOUT, LOW);
        delay(1);
        digitalWrite(PWMOUT, HIGH);
        delay(1);
        digitalWrite(PWMOUT, LOW);
        delay(1);
        digitalWrite(PWMOUT, HIGH);
        delay(Function);
        digitalWrite(PWMOUT, LOW);
        }
      else {delay(10);}                                  // Niet te snel toetsen uitlezen, ongeveer zelfde tijd also klok pulsen
      
      }
    while (Function < 1000);                             // Altijd loopen
}
 

Link to post
Share on other sites
  • 4 weeks later...

Hello Gaston,

 

Thanks, but I have read that already of course. I was hoping to find help in the Energia environment, based on the touch library. My knowledge of low level prgramming is too limited at this moment to understand TI examples, but I think I will dive into that and try to make my own direct implementation, so I can adjust variables. Hope to get it to work. I now made it with a wire touching the pads to make them 0 or 1, and then the system works very reliable, just have to get the touch buttons right and 100% dependable.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...