[CCC DEV] Suggested change to level.to.signal

Steve Pretty steve.g.pretty at btinternet.com
Thu Jan 27 20:29:27 GMT 2011


If you decide to adopt my suggested change to digital.input, it may be 
desirable to modify the functionality of level.to.signal

In the plumbing book, some of the example programs use a push button 
attached to an arduino pin. The state of the button is read using 
digital read (via the button.press PROC).  At present, if the button is 
pushed and released, digital.input will send a single HIGH message. This 
means the LED in the plumbing book examples comes on at the first push, 
and goes off at the second.

If digital.input is modified to send HIGH when the button is pressed and 
low when released, the LED goes on when pressed, and off when released. 
That is not what the readers would expect when they see the work 
"toggle" in the code.

I would suggest that the PROC level.to.signal is changed so that it 
implements a rising edge detect function - i.e. it sends signal only 
when it receives HIGH:

--{{{ PROC level.to.signal
--* Convert a LEVEL to a SIGNAL.
-- Consumes a stream of LEVEL values, and emits a SIGNAL
-- for each time a HIGH LEVEL is received. LOW LEVEL signals
-- are black holed.  The PROC effectively acts as a rising edge detector.
--
-- @param in Input LEVEL values.
-- @param out Output SIGNALs.
PROC level.to.signal (CHAN LEVEL in?, CHAN SIGNAL out!)
   LEVEL any:
   WHILE TRUE
     SEQ
       in ? any
       IF
         any = HIGH
           out ! SIGNAL
         TRUE
           SKIP
:
--}}}


Steve




More information about the developers mailing list