Appendix A 471
Additional Lab Exercises
General Programming Techniques
Solution 2—Apple Bagger
Figure A-2 gives another solution using more objects.
Figure A-2. Apple Bagger, Solution 2
Key Points
n Start: Using a
Start object for this program is redundant, since you can
use the Run button on the main menu bar.
Start is best used when you
have two programs on a screen, and you want to be able to run them
independently. Or you have a program with a feedback loop, and you
want to define where to initiate execution.
n Shift Register: You use a
Shift Register to access the previous
values of the output. In solution 2, the
Counter is keeping a running
count of every apple before it is weighed, so the count must be reduced
by one when the total weight exceeds 10.
n Gate: The
Gate is used to hold the output until another action occurs and
activates its sequence pin. Here, when the condition
A<=10 is no longer
true, the
Else pin on the If/Then/Else object activates the gate.