Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
On pages 27 and 27 of the PicAxe manual they discuss switches and how to wire them.
The diagram shows a 1K resistor between one leg of the switch and the PicAxe pin. This
is important because the current flow must be very low. The other leg of the switch is
connected through a 10K resistor to either +5 or 0.
First if the switch on pin 3 is AND the switch on pin 1 are both pressed they will read
HIGH on both and the statement is TRUE, so the command on the rest of the line is
executed. i.e. Then Cease which means goto the Cease sub routine and do whatever it
says, but dont come back! The command goto is understood in this line and can be
omitted. (Programming 204 .... ;-)
When we look at cease we can see that it just turns off the PWM at pin 2 by making the
period 0. Remember that the period is the size of the frame in which the duty is carried
out. No frame, no power to the motor. And then it sends the program back to Top.
Thats not quite like starting over because it doesnt include the original motor start that
happened with the first run of the program, so the motor remains stopped.
The next two lines look for a single button push and react accordingly. If no buttons are
pushed the program falls thru to the next command which is GoTo Top
AS you can see the program jumps around a LOT! Every time the LED flashes the
program has run all the switch checks and acted on the instructions.
New terms are:
Goto and Gosub. These terms direct the program to a block of code that does a specific
task, like blink an LED, increase the speed of a motor, etc.
Goto is a one-way-trip and once the instructions have been carried out the operation
continues to the next set of instructions. If there are none, the program stops!
Gosub directs the program to a routine that ends in the command return, which send the
program back to the line that sent it there, and the program continues.
IF ... THEN is used to test to see if something is true. If the answer is true action
described after the word THEN is performed. If the answer is false the instructions after
THEN and ignored and the program drops through to the next line.
AND between IFs means that all of the test results must be true for the THEN to be
executed. (There can be multiple ANDs between IF and THEN).
OR could also be used in place of AND to test for either of two conditions. Again,
multiple ORs can be between IF and THEN.