In this circuit tutorial we are going to look at the concepts of delays. If you ever used jeenodes or arduino’s (if your reading this then I am sure you have) you will have wanted to flash an LED. There are lots of ways to do this, but most start with the arduino delay() function. You power your LED, wait (delay) for 500ms and then you remove power.
Its only in the next set of tutorials that we let loose on actual hardware (like jeenodes), we are still in the ‘soft’ circuit environment right now, but we can still experiment with the concept of ‘delay’.
We are going to build upon circuit 5 by adding the ‘Delay’ gadget.
Change to your housemon folder, and get circuit 6:
$ ./cirget circuit 6 $ ./cirget -y
Here is the circuit:
#Read a Text file, output first delayed by 200ms, then sent to console line prin ter. --- init: gadgets: - name: "dummy" type: "Pipe" - name: "rft" type: "ReadFileText" - name: "p" type: "Printer" - name: "d" type: "Delay" wires: - from: "rft.Out" to: "d.In" - from: "d.Out" to: "p.In" feeds: - data: "setup.json" to: "rft.In" - data: "200ms" to: "d.Delay" labels: - external: "In" internal: "dummy.In" - external: "Out" internal: "dummy.Out"
Line (16-17) adds a new gadget called ‘Delay’. The wires are adjusted to send the output from ‘ReadFileText’ into ‘Delay’ and then out of ‘Delay’ and into the ‘Printer’. Within the feeds section, we provide our filename to ‘ReadFileText’, and a “200ms” parameter to the .Delay pin of the ‘Delay’ gadget. The Delay gadget take a ‘duration’ as a parameter (sent to the .Delay pin). Delays are expressed as either Hour, Minutes or Seconds, or combinations of these. Some examples are:
- 1m30s – 1 Minute and 30 Seconds
- 90s – 1 Minute and 30 Seconds (expressed as Seconds only)
- 1h30m – 1 Hour and 30 Minutes
- 90m – 1 Hour and 30 Minutes (expressed as Minutes only).
So – we are telling the ‘Delay’ gadget to delay any message it receives by 200 Milliseconds, before it passes the message out of its .Out pin.
I am sure you can guess what will happen when we run the circuit?
The output looks pretty much as per the previous tutorial except our circuit is a little larger (we added Delay). But the way in which the output was sent to the console changed – did you notice that each line was delayed (only by 200ms), but the delay should have been noticeable!.
I mentioned in the previous post about ‘Tagged’ messages. Those messages are in this circuit also. I also mentioned that some gadgets are smart enough to be able to use these ‘Tagged’ messages to good effect.
Notice here that the ‘Delay’ gadget got passed these ‘tags’ from the ‘ReadFileText’ but it did NOTHING with them, it simply passed the message through unchanged. This is another important point. If a gadget does not know how to handle a tagged message specifically, it should simply ignore it and pass it through unchanged to the next gadget (that may be able to handle the tag properly).
In a future post, we will use this ‘Delay’ and a custom jeenode sketch to simulate the good old ‘BLINK’ sketch, but entirely driven from housemon.
Until then, we have more gadgets and concepts to cover in the next tutorials.