beautypg.com

Elenco Snap Circuits SnapMicro I Deluxe ® User Manual

Page 27

background image

26

Project 3: The Value of Comments and Checking Program Length

Sometimes it can be hard to remember the purpose for each step of the program.

Comments (an

explanation after the apostrophe (‘) symbol) can make each line of a program much easier to understand

and remember. These comments are ignored by the computer when it downloads a program to the

micro-controller.

A label (e.g.

main: in the program above) can be any word (apart from keywords such as ‘switch’), but

the label must begin with a letter. A label must also end with a colon (:). The colon ‘tells’ the program

editor that the word is a label.

The previous program uses the

wait command. The commands wait and pause both create time

delays. However

wait is used with whole seconds, pause can be used for shorter time delays

(measured in milliseconds or 1000th of a second).

Wait must be followed by a number between 1 and 65.

Pause must be followed by a number between 1 and 65535.

It is also a good programming technique to use tabs (or spaces) at the start of lines without labels so

that all the commands are neatly aligned. The term

‘white-space’ is used by programmers to define

tabs, spaces and blank lines, and the correct use of white-space can make the program listing much

easier to read and understand. Note these changes made to the previous program and shown here.

This manual is related to the following products: