It could be because when you're connected by bluetooth it's sending and receiving packets to your PC every (i think) 20ms or so, which could very likely overlap with the advertising packets that it is trying to receive (and that appear only every 300ms or so).
You could try something like:
var found = [];
setWatch(function() {
digitalPulse(LED,1,10);
NRF.sleep();
NRF.findDevices(function(devices) {
digitalPulse(LED2,1,10);
found = devices;
NRF.wake();
}, 4000);
}, BTN, { edge:"rising",debounce:50,repeat:true });
and you could upload, press the button, then connect again after the 5 seconds and see what was in 'found'?
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.
I guess you're still connected by Bluetooth?
It could be because when you're connected by bluetooth it's sending and receiving packets to your PC every (i think) 20ms or so, which could very likely overlap with the advertising packets that it is trying to receive (and that appear only every 300ms or so).
You could try something like:
and you could upload, press the button, then connect again after the 5 seconds and see what was in 'found'?