[C.CC USERS] Button press counter

Ian Armstrong armstri at allegheny.edu
Sat Nov 17 00:55:17 GMT 2012


All,

I am working on a project that involves switching LED pattern based on
pressing a button.  I would like to have multiple "modes" that could be
cycled through by pushing a button multiple times.  Im unsure of how to
count the number of pushes that occur.  This is what I have so far.

#INCLUDE "plumbing.module"
PROC number.pushes (CHAN SIGNAL push?, CHAN INT num.pushes!)
  CHAN INT pushes:
  WHILE TRUE
    IF push ? SIGNAL
      SEQ
        num.push := num.push +1
        pushes ! num.push
        IF num.push > 4
          num.push := 0

:

PROC main()
  CHAN SIGNAL s:
  INT num.pushes:
  CHAN INT pushes:
  SEQ
    serial.setup(TX0,9800)
    PAR
      button.press(2,s!)
      number.pushes(s?, pushes!)
      SEQ
        pushes ? pushes
        serial.write.int(TX0,pushes)
:

I am unsure of how to implement what I have highlighted as red text.  Am I
at least on the right track?

Looking forward to any thoughts anyone might have.

Thanks,
Ian Armstrong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.concurrency.cc/pipermail/users/attachments/20121116/352fcefb/attachment.htm>


More information about the users mailing list