Skip to main content
Tweeted twitter.com/StackElectronix/status/966158888243486725
added 299 characters in body
Source Link
rrz0
  • 1.2k
  • 1
  • 22
  • 44

Software Debouncing to detect length ofif switch presshas been pressed for T seconds

Comment by @DiBosco clarifies further:

So what you're saying is that if you get a switch pressed for, say, twenty counts and it is released that acts as normal press that does one function, and if it is pressed and held down for two seconds or so it carries out a different function...

Software Debouncing to detect length of switch press

Software Debouncing to detect if switch has been pressed for T seconds

Comment by @DiBosco clarifies further:

So what you're saying is that if you get a switch pressed for, say, twenty counts and it is released that acts as normal press that does one function, and if it is pressed and held down for two seconds or so it carries out a different function...

fix formatting
Source Link
Dave Tweed
  • 178.3k
  • 17
  • 242
  • 418
int buttonPress (void)    
{
  static int downCount= 0; // static = value isn't lost between calls.

  int currentButton = ((IO0PIN & 0x00000200) == 0x00000200); 

  if (currentButton ) { // button is down
    
    if (downCount == 5) { // button has been down for 5 counts
      downCount++;      // increase the count so we don't trigger next time
      return 1;
    } else {              // some count other than 5
      if (downCount < 5)  // increase if it's less than 5
        downCount++;
    }
  } else   {    // button is up
    downCount = 0; 
    }
  return 0;
}   
if (currentButton ) {   // button is down

  if (downCount == 5) { // button has been down for 5 counts
      downCount++;      // increase the count so we don't trigger next time
            while (downCount > 5) { 
                if (debounce == 300000) {
                    flag_5SEC = 1;
                 }
                else if (debounce < 300000) {
                    debounce++;
                }
            }
      return 1;
    } else {              // some count other than 5
      if (downCount < 5)  // increase if it's less than 5
         downCount++;
    }
  }
int buttonPress(void)   {
static int downCount= 0; // static = value isn't lost between calls.

int currentButton = ((IO0PIN & 0x00000200) == 0x00000200); 

  if (currentButton ) { // button is down
    
    if (downCount == 5) { // button has been down for 5 counts
      downCount++;      // increase the count so we don't trigger next time
      return 1;
  } else {              // some count other than 5
    if (downCount < 5)  // increase if it's less than 5
       downCount++;
    }
  } else   {    // button is up
    downCount = 0; 
    }
  return 0;
}   
if (currentButton ) {   // button is down

  if (downCount == 5) { // button has been down for 5 counts
      downCount++;      // increase the count so we don't trigger next time
            while (downCount > 5) { 
                if (debounce == 300000) {
                    flag_5SEC = 1;
                 }
                else if (debounce < 300000) {
                    debounce++;
                }
            }
      return 1;
    } else {              // some count other than 5
      if (downCount < 5)  // increase if it's less than 5
         downCount++;
    }
  }
int buttonPress (void) 
{
  static int downCount= 0; // static = value isn't lost between calls.

  int currentButton = ((IO0PIN & 0x00000200) == 0x00000200); 

  if (currentButton ) { // button is down
    
    if (downCount == 5) { // button has been down for 5 counts
      downCount++;      // increase the count so we don't trigger next time
      return 1;
    } else {              // some count other than 5
      if (downCount < 5)  // increase if it's less than 5
        downCount++;
    }
  } else   {    // button is up
    downCount = 0; 
  }
  return 0;
}   
if (currentButton ) {   // button is down

  if (downCount == 5) { // button has been down for 5 counts
    downCount++;      // increase the count so we don't trigger next time
    while (downCount > 5) { 
      if (debounce == 300000) {
        flag_5SEC = 1;
      } else if (debounce < 300000) {
         debounce++;
      }
    }
    return 1;
  } else {              // some count other than 5
    if (downCount < 5)  // increase if it's less than 5
      downCount++;
  }
}
deleted 23 characters in body
Source Link
rrz0
  • 1.2k
  • 1
  • 22
  • 44
if (currentButton ) {   // button is down

  if (downCount == 5) { // button has been down for 5 counts
      downCount++;      // increase the count so we don't trigger next time
            while (downCount > 5) { 
                debounce++;
                  if (debounce == 300000) {
                    flag_5SEC = 1;
                 }
                else if (debounce < 300000) {
                    debounce++;
                }
            }
      return 1;
    } else {              // some count other than 5
      if (downCount < 5)  // increase if it's less than 5
         downCount++;
    }
  }
if (currentButton ) {   // button is down

  if (downCount == 5) { // button has been down for 5 counts
      downCount++;      // increase the count so we don't trigger next time
            while (downCount > 5) { 
                debounce++;
                  if (debounce == 300000) {
                    flag_5SEC = 1;
                 }
                else if (debounce < 300000) {
                    debounce++;
                }
            }
      return 1;
    } else {              // some count other than 5
      if (downCount < 5)  // increase if it's less than 5
         downCount++;
    }
  }
if (currentButton ) {   // button is down

  if (downCount == 5) { // button has been down for 5 counts
      downCount++;      // increase the count so we don't trigger next time
            while (downCount > 5) { 
                if (debounce == 300000) {
                    flag_5SEC = 1;
                 }
                else if (debounce < 300000) {
                    debounce++;
                }
            }
      return 1;
    } else {              // some count other than 5
      if (downCount < 5)  // increase if it's less than 5
         downCount++;
    }
  }
added 122 characters in body
Source Link
rrz0
  • 1.2k
  • 1
  • 22
  • 44
Loading
add material from comment
Source Link
Dave Tweed
  • 178.3k
  • 17
  • 242
  • 418
Loading
Source Link
rrz0
  • 1.2k
  • 1
  • 22
  • 44
Loading