It was using a trick specific to the AVR architecture for pull-ups.
I think you should probably to change the timestamp variables from "long" to "unsigned int"
and any other longs to ints for Due.
Time values should have been "unsigned long" in the first place, but I can't see anything
else obviously a problem.
A good way to deal with types is use explicitly sized types: change long to int32_t and
unsigned long to uint32_t. Things that are already just int can stay int, usually.
int reader = 0;
void setup() {
Serial.begin(115200);
Serial.println("Start ...");
pinMode(48, INPUT);
digitalWrite(48, HIGH); // turn on pullup resistors
}
// the loop function runs over and over again forever
void loop() {
reader = digitalRead(48);
Serial.println(reader);
delay(250);
}
This works ok. If I press the button I get 0 otherwise I get 1. So generally this should work.
Now I changed the code in the clickbutton constructor:
The only solution that works well is an external Pullup and using of constructor 2 (ClickButton::ClickButton(uint8_t buttonPin, boolean activeType)).
But the strange thing is ... This code works great (now with INPUT_PULLUP):
int reader = 0;
void setup() {
Serial.begin(115200);
pinMode(46, INPUT_PULLUP);
}
// the loop function runs over and over again forever
void loop() {
reader = digitalRead(46);
Serial.println(reader);
delay(250);
}
I´ve attached my test sketch. Maybe there is a mistake?
One thing that may confound the issue is that the internal pullups on the Due are
very weak - like 50k or more, IIRC. Touching the wiring might affect things.
For long cable runs add a 4k7 external pullup anyway.
Actually I looked at the code for digitalWrite on the Due - they've faked it up
to behave like the Atmel chips and turn on pull-ups if the pin is currently an
INPUT...
Anyway the pinMode (..., INPUT_PULLUP) is the clean way to do these
things now, it documents intent in the setup() function nicely.