Subroutines in PBASIC gosub Similar to goto but remembers a return - - PowerPoint PPT Presentation

subroutines in pbasic
SMART_READER_LITE
LIVE PREVIEW

Subroutines in PBASIC gosub Similar to goto but remembers a return - - PowerPoint PPT Presentation

Subroutines in PBASIC gosub Similar to goto but remembers a return Example -- LED flash flash3: in5 = 1 for x = 1 to 3 pause 300 in5 = 0 pause 300 in5 = 1 next return Using a subroutine To flash LED after chip is reset


slide-1
SLIDE 1

Subroutines in PBASIC

■ gosub

– Similar to goto but remembers a return

■ Example -- LED flash

flash3: in5 = 1 for x = 1 to 3 pause 300 in5 = 0 pause 300 in5 = 1 next return

slide-2
SLIDE 2

Using a subroutine

■ To flash LED after chip is reset

variable declarations gosub flash3 main:

rest of code

■ Do not goto a subroutine!

– Effect of the return is unpredictable

■ Do not if to a subroutine!

if X > 0 then flash3

slide-3
SLIDE 3

Possible tests of an if

■ if test then label ■ Relational operators

= equal <> not equal > greater than < less then >= greater than or equal <= less than or equal

slide-4
SLIDE 4

More tests of an if

■ Logical operators

– One condition operators

NOT Condition is false

– Two condition operators

AND Both conditions are true OR At least one condition is true XOR Exactly one condition is true

slide-5
SLIDE 5

Printing

■ To print a message

debug “Starting…“

■ To print a value with name

debug ?x

■ To print the value without name

debug x

■ To clear the screen

debug CLS