[C.CC USERS] 3 Binkin lights not in parallel

Matt Jadud matt at jadud.com
Sun Feb 27 13:24:53 GMT 2011


Hi Lar,

On Sun, Feb 27, 2011 at 06:55, cljacobsen at gmail.com
<cljacobsen at gmail.com> wrote:
> The way we could implement blink in order to fix this would be to do
> something like the following:
>  init {
>    delay_time = 500
>    start_time = read_time()
>    wait_until_time = start_time
>  }
>  do_forever {
>    turn_on_led()
>    wait_until_time = wait_until_time + delay_time
>    wait_until(wait_until_time)
>    turn_off_led()
>    wait_until_time = wait_until_time + delay_time
>    wait_until(wait_until_time)
>  }

> The only thing we could do better now is to, instead of reading the
> time in each blink process, to pass in the same starting time to all
> the processes. As the second bit of code is now, the processes would

Below is a small piece of code that might correctly implement what
Christian is describing. Note that this code runs on the TVM on the
Desktop; you'd have to swap out "useful" for "plumbing" and use the
correct delay constant on the Arduino. (The desktop tracks time in
microseconds, while the Arduino gives us a millisecond clock.)

Assuming I don't have this wrong, you could use this as a starting
point for your own LED process. Instead of printing, you can use

digital.write(led.pin, LOW)

and

digital.write(led.pin, HIGH)

to turn pins for LEDs on and off, and use something like sync.delay to
get them in sync.

Cheers,
Matt

#INCLUDE "useful.module"

PROC sync.delay (INT s, VAL INT us)
  TIMER tim:
  SEQ
    s := s PLUS us
    tim ? AFTER s
:

VAL INT MS.ARDUINO IS 1:
VAL INT MS.DESKTOP IS 1000:
VAL INT DELAY IS 1000 * MS.DESKTOP:

PROC main (CHAN BYTE kyb, scr, err)
  TIMER tim:
  INT start:
  SEQ
    tim ? start
    PAR

      INITIAL INT s1 IS start:
      WHILE TRUE
        SEQ
          out.string("x1*n", 0, scr!)
          sync.delay(s1, DELAY)

      INITIAL INT s2 IS start:
      WHILE TRUE
        SEQ
          out.string("y1*n", 0, err!)
          sync.delay(s2, DELAY)
:



More information about the users mailing list