I reckon what you'd probably want to short out the two pins in the second circuit is a Relay - which really does physically connect two contacts together when you want it to. There are some relay modules that you can get really cheap now that are really easy to drive from Espruino.
Just connect one of those up to a pin on Espruino - then it's basically the software... Something like this should work:
var RELAY_PIN = A0; // where you connected the relay
var timeStamps = [
// Ordered list of timestamps (as seconds since 1970)
];
function connectCircuit() {
digitalWrite(RELAY_PIN, 0); // turn relay on - generally the logic is inverted
setTimeout(function() {
// relay off after 1 sec
digitalRead(RELAY_PIN); // some relays are 5v, so you need to make the pin an input
queueTimer(); // and now see if there are other timer tasks
}, 1000);
}
function queueTimer() {
var nextTime = timeStamps.shift(); /// remove first element from the array
if (nextTime===undefined) return; // no more timeStamps?
var delaySecs = getTime()-nextTime;
if (delaySecs<=0) // maybe it's already happened? Do it now
connectCircuit();
else // otherwise do it after a delay
setTimeout(connectCircuit, delaySecs*1000);
}
You'd want to turn on the 'set time' option in the Web IDE's settings though, to ensure that when you write code to Espruino it sets the time on it up correctly.
Sometimes having a 'proper' timestamp is overkill though, and you might just want to have 'seconds since a button was pressed'. That's not a huge tweak though.
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.
Hi,
I reckon what you'd probably want to short out the two pins in the second circuit is a Relay - which really does physically connect two contacts together when you want it to. There are some relay modules that you can get really cheap now that are really easy to drive from Espruino.
Just connect one of those up to a pin on Espruino - then it's basically the software... Something like this should work:
You'd want to turn on the 'set time' option in the Web IDE's settings though, to ensure that when you write code to Espruino it sets the time on it up correctly.
Sometimes having a 'proper' timestamp is overkill though, and you might just want to have 'seconds since a button was pressed'. That's not a huge tweak though.
Hope that helps!