Next, lets experiment with adc(). You can find it in the Plumbing documentation. Draw the process in your notebook, so you know what it should look like when included in a process diagram.
Now, write a new process called show.int(). In an infinite loop (WHILE TRUE) it should, in SEQuence:
- SIGNAL the adc() process (to start a reading)
- read the INT that adc() produces
- Output that number to the screen.
- Output a newline
You can generate a newline in your printed output this way:
serialWrite("*n")
In Java, you would have written \n. In occam, you write *n. Each language has its syntax.
Wire this new process up with adc() and run them in parallel in a main() process. If you've wired your circuit up correctly, you should be able to see the values read from the adc() process printed to your screen.
NOTE
SIGNAL channels are simpler than any other kind of channel. You still declare them as you would anything else:
CHAN SIGNAL s:
However, to write to them, you just say
s ! SIGNAL
And, to receive at the other end, you write
s ? SIGNAL
Put simply, a SIGNAL isn't a value. It's more like a submarine ping. Or, if you prefer, a "high-five." We added SIGNALs to occam-π this past summer, because we wanted a really simple way for one process to communicate with another.
QUESTIONS
- show.int consumes data and displays it to the screen. In terms of its channels in and out, what pattern does it most resemble?
- What happens if you comment out the line for signaling the ADC? Why?