[C.CC USERS] Occam-Pi programing question
Matt Jadud
matt at jadud.com
Thu Aug 30 23:23:52 BST 2012
Hi Bryant,
The delay() process sleeps the process it is in for 'n' milliseconds.
(Well, at *least* that many milliseconds. It will never be less.)
SEQ
... do stuff ...
delay (1000) -- Sleep for 1 second
... do stuff ...
delay (3000) -- Sleep for 3 seconds
I personally like a constant
VAL INT SECONDS IS 1000:
at the top of my program. Then, I can write:
SEQ
...
delay (1 * SECONDS)
...
Now, depending on how things work, you could make this a very parallel system:
PROC pump.on (CHAN SIGNAL s?)
WHILE TRUE
SEQ
... do stuff
s ? SIGNAL -- WAIT FOR A SIGNAL
... turn pump on
:
Then, a delayN process:
PROC line.delay (VAL INT sec, CHAN SIGNAL s.in?, s.out!)
WHILE TRUE
SEQ
s.in ? SIGNAL
delay(sec * SECONDS)
s.out ! SIGNAL
:
Finally, an equivalent process to the above that turns OFF the pump:
PROC pump.off (CHAN SIGNAL s?)
WHILE TRUE
SEQ
... do stuff
s ? SIGNAL -- WAIT FOR A SIGNAL
... turn pump off
:
The process network would then look like... (see attached).
That's a schematic, anyway. You could then wrap that all up in another proc:
PROC duty.cycle (VAL INT on, off)
...
and use the values 'on' and 'off' to control how long each pump is on and off.
That's a start on answering your question... there are other ways you
could do this, but it depends on what else is in your system and how
you want all those parts to interact. (In other words: since we're
talking about program code, there are many ways to do what you want to
do.)
Feel free to post your code (or throw it in a Github Gist, etc.) for
more specific help on what you're trying to do... or, just ask more
questions.
Cheers,
Matt
On Thu, Aug 30, 2012 at 4:28 PM, Bryant Nelson
<bryant.p.nelson at gmail.com> wrote:
> All,
>
> I'm new to programming in occam-pi, but I have gone through the plumbing
> book. I'm using an Arduino uno and some relays to control powerheads in my
> reef aquarium. The goal is to simultaneously control 3 pumps with variable
> rates and duty cycles. Right now I am using the blink commands and
> everything is working fine, however this isn't exactly what I want. The
> blink function turns the pumps on for a set time and off for the same amount
> of time. I'm trying to turn the pump on for 1s and off for 3s and can't seem
> to find any info on turning individual pins on/off or delay commands. Can
> somebody help me out?
>
> Bryant
>
> _______________________________________________
> users mailing list
> users at concurrency.cc
> http://lists.concurrency.cc/mailman/listinfo/users
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pump-duty-cycle.png
Type: image/png
Size: 19395 bytes
Desc: not available
URL: <http://lists.concurrency.cc/pipermail/users/attachments/20120830/4d0f778e/attachment-0001.png>
More information about the users
mailing list