-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It takes ~ 35 ms to for isTouch() resistive to return the correct value #458
Comments
This is by design, as in codal-core, the While this is expected, for a user shorting the pins (and this came from a science experiment where this block was used as a water level detector, where water connects P0 to GND) and having an "if" statement or a "while" loop, it means that the first reading can be "incorrect" if the default pin state is "pressed". What would be the best way to ensure the first int Button::isPressed()
{
if (_pin.obj != this)
{
if (_pin.obj != NULL)
_pin.obj->releasePin(_pin);
_pin.obj = this;
_pin.setPolarity( polarity == ACTIVE_HIGH ? 1 : 0);
_pin.setPull(pullMode);
this->status |= DEVICE_COMPONENT_STATUS_SYSTEM_TICK;
// If the button is "pressed" it will only register as such after
// DEVICE_BUTTON_SIGMA_THRESH_HI ticks in the periodicCallback().
// To prevent a false negative when calling this method, start sigma
// at a couple of ticks away and wait.
if (buttonActive()) {
sigma = DEVICE_BUTTON_SIGMA_THRESH_HI - 1;
fiber_sleep(2 * SCHEDULER_TICK_PERIOD_US / 1000);
}
}
return status & DEVICE_BUTTON_STATE ? 1 : 0;
} |
I think that would fire the DOWN event as if it had changed to pressed. How about...
|
I think I added the longer delay here due to the large amount of debouncing needed when using capacitate inputs... So we probably wat to be careful not to break that as we address this issue. Suggest we perhaps:
|
Connecting a crocodile clip between P0 and ground, and then calling
uBit.io.P0.isTouched(TouchMode::Resistive)
returnsfalse
for around 35 milliseconds.As P0 is grounded, the correct behaviour should be to return 1 (touched) from the first time it's called.
Output:
Which returns the wrong value 9 times, with a 4ms delay = 36 ms.
A mode detailed example with precise timings can be expanded here
Hex: example2.hex.zip
The text was updated successfully, but these errors were encountered: