Bouncing

ON WAY

history short

  • pinMode(2,INPUT_PULLUP) high is idle level

  • switch to ground

  • 39 nF between input on ground (pict nr 2 from top)

  • lock in ISR to intr with xx msecs is ignored

    • Arduino code (for UNO) in buttom deadtime is 10 msec

    • So dont press button more then 20 times a second …

newest img in top

bounce100msecbuttonstorcapacitor.png 470 nF

 

bounce50mseccapacitor.png 39 nF

 

bounce200msecbuttoncapacitor.png 39 nF

 

bounce100msecbuttoncapacitor.png

 

bounce50msecpin.png

 

bounce50msecbutton.png

 

bounce5msecpin.png

 

bounc1msecbutton.png

 

bounce1msecpin.png

 

bounce5msec.png

 
/*
    INTERRUPTS

    Arduino uno/mega

    https://jensd.dk/edu/doc/arduino/ards.html

    is an pin overview . Look for pins marked INT0, INT1,...

    Board     int.0   int.1   int.2   int.3   int.4   int.5

  Uno, Ethernet 2        3
  Mega2560      2        3       21      20       19      18


*/


const int pin = 2;  //define interrupt pin to 2
const int respPin = 13;
volatile int state = LOW;  // To make sure variables shared between an ISR
//the main program are updated correctly,declare them as volatile.


volatile int intCnt = 0;
volatile unsigned long last = 0;
boolean p8 = false;
void blinkk() {
  //ISR function


  if (30 <= (millis() - last)) { // at least 30 msec between two intr
    intCnt++;
    last = millis();
    state = !state;  //toggle the state when the interrupt occurs
    digitalWrite(8, (p8 = !p8));
  }
}


void setup() {
  Serial.begin(115200);
  pinMode(respPin, OUTPUT);  //set pin 13 as output

  pinMode(pin, INPUT_PULLUP);  // intr on pin 2 (UNO)
  pinMode(8, OUTPUT);          // for togling every time an intr is received
  digitalWrite(8, LOW);
  attachInterrupt(digitalPinToInterrupt(pin), blinkk, FALLING);  //CHANGE);
}

int oldCnt = 0;
void loop() {
  /*
  if (old != intCnt) {
    Serial.println(intCnt);
    old = intCnt;
  }
  */
  // DEBUG
  if (oldCnt != intCnt) {
    oldCnt = intCnt;
    Serial.println(oldCnt);
  }
  digitalWrite(respPin, state);  //pin 13 equal the state value
}

as raw file

Jens