IS bounce 2 compatible with teensy 3.1?

Status
Not open for further replies.

neutron7

Well-known member
I would like to use bounce 2 in my project because there are 2 versions (of my project)

the setup checks for a pin being low and then changes the mapping of the switches to pins accordingly. unfortunately bounce 1 wants you to assign pins before setup.

if someone has tried it and it works, that would save me some potential grief!

thanks
n
 

yes that is the one.

my sourcecode is very huge to post here, but i initialize a button with a variable called "FXButton" which was set to the pin (3) that is used in the first hardware version.

Code:
Bounce FXCycleButton = Bounce(FXButton, 20);

then in setup, i check a pin to see if there is anything connected (an LED that is on one version but not the other)

Code:
void setup() {

  pinMode(aout2, OUTPUT);//ignore
  pinMode(oSQout, OUTPUT);//ignore
  pinMode(31, INPUT_PULLUP);//turn this to an input to check for presence of LED. (hw2 detect)

  if (digitalRead(31) == 0) { //detect if an LED is on the pin. if so, then it is 2.0 hardware module.
    IsHW2 = 1;

now i have detected "is hardware 2" and need to change the pin that the FXCycleButton bounce object is attached to.

I would prefer not to use the bounce2 library if possible because it means users will have another thing to download, and there are quite a lot of these out in the wild (neutron sound orgone accumulator)

i hope that makes sense.
 
mmh, if it's just the one switch, couldn't you just use some custom code? you can still use bounce for the others.

unless i'm missing something:

Code:
if (IsHW2)  FXButton = thispin;
else FXButton = thatpin;


and something like :

Code:
 if (!digitalReadFast(FXButton) && (millis() - _TIMESTAMP > _DEBOUNCE)) {
   
     _TIMESTAMP = millis();
    // do something

}
 
I haven't tested that "Bounce2" copy, but I just looked at its code. It certainly looks like it should work.

Is there any problem you're seeing?
 
Bounce2 works, but downloading and installing the library is a problem for some people.
i did not realize it was just counting millis though(i thought it was using interrupts), i will just add my own function for it.

thanks for the help!
 
I found an easy fix. with Bounce1 you CAN reassign the pin number after creating the bounce.

create the bounce as normal before setup

Code:
Bounce FXCycleButton = Bounce(FXButton, 20);

then after testing the pin in setup (which changes the value of FXButton pin)

Code:
FXCycleButton = Bounce(FXButton, 20);
 
Status
Not open for further replies.
Back
Top