12.07.2015 Views

PICAXE Manual Section 1 - TechnoPujades - Free

PICAXE Manual Section 1 - TechnoPujades - Free

PICAXE Manual Section 1 - TechnoPujades - Free

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

www.picaxe.co.uk<strong>Section</strong> 1 61GETTING STARTEDTutorial 2 - Using Symbols, Comments & White-spaceSometimes it can be hard to remember which pins are connected to whichdevices. The ‘symbol’ command can then be used at the start of a program torename the inputs and outputs.symbol LED = 4symbol buzzer = 2‘ rename output4 ‘LED’‘ rename output2 ‘buzzer’main:high LEDlow buzzerpause 1000low LEDhigh buzzerwait 1goto main‘ make a label called ‘main’‘ LED on‘ buzzer off‘ wait 1 second (1000 ms)‘ LED off‘ buzzer on‘ wait 1 second‘ jump back to the startRemember that comments (an explanation after the apostrophe (‘) symbol) canmake each line of a program much easier to understand. These comments areignored by the computer when it downloads a program to the <strong>PICAXE</strong>A label (e.g. main: in the program above) can be any word (apart from keywordssuch as ‘switch’), but must begin with a letter. When the label is first defined itmust end with a colon (:). The colon ‘tells’ the computer that the word is a newlabel.This program uses the wait command. The commands wait and pause bothcreate time delays. However wait can only be used with whole seconds, pause canbe used for shorter time delays (measured in milliseconds (1000 th of a second)).Wait can be followed by a number between 1 and 65.Pause can be followed by a number between 1 and 65535.It is also a good programming technique to use tabs (or spaces) at the start oflines without labels so that all the commands are neatly aligned. The term ‘whitespace’is used by programmers to define tabs, spaces and blank lines, and thecorrect use of white-space can make the program listing much easier to read andunderstand. See the example program on the next page, where code between thefor...next commands is also indented with a tab for clarity.Note:Some early BASIC languages used ‘line numbers’ rather than labels for ‘goto’commands. Unfortunately this line number system can be inconvenient to use,because if you modify your program by later adding, or removing, lines of codeyou then have to modify all the line numbers within the ‘goto’ commandsaccordingly. The label system, as used in most modern BASIC languages,overcomes this problem automatically.revolution(c) Revolution Education Ltd. Email: info@rev-ed.co.uk Web: www.rev-ed.co.ukVersion 6.9 07/2009All rights reserved.61

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!