@allObjects thanks to your suggestions I have played with different timers and debounce values again and I think I'm getting somewhere.
@Gordon it's even less reliable this way, it's difficult to describe LED's behavior now so I have changed the code to use console.log and it looks interesting.
First try:
var door = new Pin(A8); //pull-up
E.on("init", function () {
door.mode("input");
});
function doorOpenedHandler() {
console.log("door opened");
}
function doorClosedHandler() {
console.log("door closed");
}
setWatch(function () {
doorOpenedHandler();
}, door, {repeat: true, edge: "falling", debounce: 500});
setWatch(function () {
doorClosedHandler();
}, door, {repeat: true, edge: "rising", debounce: 500});
1v81 Copyright 2015 G.Williams
>echo(0);
=undefined
>save()
=undefined
Erasing Flash.....
Writing.....
Compressed 81600 bytes to 2942
Checking...
Done!
// I'm starting with closed switch
door closed
>door.read()
=true
// I'm opening the switch
door opened
>door.read()
=false
// I'm closing the switch
door opened
>door.read()
=true
// wait, what? wrong handler got called but the door value is correct
// I'm starting with closed switch again, looks like the logic has changed
door opened
>door.read()
=true
// I'm opening the switch
door closed
>door.read()
=false
// I'm closing the switch
door opened
>door.read()
=true
// I'm opening the switch
door closed
// I'm closing the switch
door closed
// wrong handler again i.e. after seeing "door closed" the last time I would expect "door opened" now
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
@allObjects thanks to your suggestions I have played with different timers and debounce values again and I think I'm getting somewhere.
@Gordon it's even less reliable this way, it's difficult to describe LED's behavior now so I have changed the code to use
console.log
and it looks interesting.First try:
Now let's try with
e.state
:Any ideas, please? Is my wiring ok?