it was usefull to have I just had not realised it had been set to 1000
probably better if it was put in the change box to start with
But many thanks to every who has helped on this
[{"id":"4b6b6cb2.275e6c","type":"change","z":"ff81c2c4.ef9ce8","name":"","rules":[{"t":"set","p":"lighton","pt":"msg","to":"20","tot":"num"},{"t":"set","p":"lightoff","pt":"msg","to":"25","tot":"num"},{"t":"set","p":"numberofblinks","pt":"msg","to":"3","tot":"num"},{"t":"set","p":"delaystart","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":900,"wires":[["d8c970d7.150a8"]]}]
//get the values of msg.* to var's
var numberofblinks = msg.numberofblinks;
var light_on_for_ms = msg.lighton;
var light_off_for_ms = msg.lightoff;
var light_delay_start = msg.delaystart;
//var run;
//how long to wait before starting the light show
var time_in_ms_to_wait_before_first_execution = light_delay_start;
or just this way:
//get the values of msg.* to var's
var numberofblinks = msg.numberofblinks;
var light_on_for_ms = msg.lighton;
var light_off_for_ms = msg.lightoff;
//var run;
//how long to wait before starting the light show
var time_in_ms_to_wait_before_first_execution = msg.delaystart;
Have you got the full coding think i got in a muddle with it now?
This is the function code that should work with your latest change node:
//get the values of msg.* to var's
var numberofblinks = msg.numberofblinks;
var light_on_for_ms = msg.lighton;
var light_off_for_ms = msg.lightoff;
//how long to wait before starting the light show
var time_in_ms_to_wait_before_first_execution = msg.delaystart || 0;
//total run time of light on and light off
var time_in_ms_to_wait_between_recursive_setTimeout = (light_on_for_ms + light_off_for_ms);
//set the count to 1
var count = 1;
var tostopit;
//function to count the number of blinks and stop timmer
function blinks() {
if (numberofblinks <= count) {
//stop the recursive setTimeout
clearTimeout(tostopit);
} else {
count++;
}
}
//function to set payload to true
function payload_true() {
//set payload to true
msg.payload = true;
node.send(msg);
//display green dot when light is on
node.status({fill: 'green', shape: 'dot', text: ' '});
}
//function to set payload to false
function payload_false() {
//set payload to false
msg.payload = false;
node.send(msg);
//clear status when payload false
node.status({});
}
//run the light show!!!!
setTimeout(function run() {
//turn the light on by setting msg.payload to true
payload_true();
//turn the light off by waiting to set the payload to false by the ammount of time light is on
setTimeout(payload_false, light_on_for_ms);
//total ammount of time light can be on or off before it runs again
tostopit = setTimeout(run, time_in_ms_to_wait_between_recursive_setTimeout);
blinks();
}, time_in_ms_to_wait_before_first_execution);
return null;
Yup
That seem great
Thanks so MUCH for everyones help on this
Awesome !!!!!! Thanks cflurin for showing me how I needed to move the blinks(); outside the inner timeout.
Well gbond now you need to make a gif or vid of it working with a fancy light show when you get it done.
The deathstar gif is pritty much what it does also I have the lego Roller coaster that has a sensor at the top to stop the motors from running & it also now triggers the Camera LED to flash 3 times before it pass it
(there is anothe sensor at the bottom to start it going again when it gets there)
All controlable from my mobil phone!!!
It flashes pritty quick so the video proberbly will not show it
nice gbond,
oh I learned about recursive timer via this link.
https://javascript.info/settimeout-setinterval
thanks gbond for helping me expand my brain.
thanks cflurin for helping put my brain back together.
Ive always used setTimeout for a one time delay trigger.
this is a loop form of using it and id never done such a thing.
I looked at that, did not understand it!. I can see how it works in there Test but not how you then put it in to node-red to do anything
I think this sort off shows it!
oh that's way more impressive than my imagination came up with from your description.
nice work!
Havent work out the best way to stop it at the station and relaunch it. Did think it might be possible to use electro magnets somehow, but not shore its possible to get anything small/powerfull enought
Also looking for a way to automaticly turn the lights on in the carts (again finding it difficult to find anything small enough to do it) (magnetic reed switch)
So just an idea for cart lights.
you could use a micro mercury switch and a 555 timer. If you can solder small.
the mercury switch would turn on the timer and the lights would stay on until timer runs out.
more done method would be to use something like this
connected to something like this
Interesting the motion sensor might work
Not so sure on the board as there is no way to get a signal to it
Garrath
the motion sensor is the signal for the board. instead of pressing the button with your finger. wire the motion sensor to the button. when the cart starts moving it will start the timer. as the timer keeps getting trigered by the motion sensor it rests the count down.
when the cart stops it will stop triggering the motion sensor. then after that the timer runs out and the lights turn off.
I get it the motion canāt work on its own then! not sure there is room for both I will investigate
well if you can solder real small you can make it compact around the motion sensor.
the arrow in the photo is pointing to the 555 timer.
the whole board is about the size of a quarter. so the timer is small.
buy the timer and needed parts to do this.
and build it all in one of the carts