Programmable Control: Writing Code with PBASIC
This section covers the following topics:
- Writing and understanding code
- IF command
- Counters
Overview
Writing and understanding code
Within your learning of programming microcontrollers, your school has the option to teach you any language they wish. There are several different types of microcontrollers available on the market today, and each has its own high-level language. What your school prefers will determine what you learn. Do not worry if you have been taught differently from any friends you have in other schools, as they all do the same things – nobody will be at a disadvantage because they are using a particular microcontroller.
Within the course, you will have to write code to ensure you are achieving the necessary outcomes, but the language you use to do this is completely up to your school.
If command
The ‘if . . . else’ command is used when a decision box is needed in your flowchart. For example, if a switch is pressed, a light will go on; else the light will stay off.

For more on this topic, have a look at our Higher Engineering Science Study Guide, pp. 42–45.
Related Videos
Watch this video to get a better grasp of how to program with Pbasic.
Activities
Quizzes
Click a link below to take a topic quiz:
Thoughts
1. A set of temporary traffic lights is required for a system of roadworks that must follow this sequence:
- The red light goes on for 12 seconds.
- The amber light then comes on for 4 seconds.
- The red and amber lights go off, and the green light switches on for 14 seconds.
- The green light switches off, and the amber light goes on for 3 seconds.
- The amber light goes off, then the system repeats.

Draw the flowchart for this sequence, and write out the code.
2. A car-manufacturing company is designing a heating system for the seats, and have decided that a microcontroller-based system should be used.
The heating system gives the option of three different settings: Off, Lo, or Hi.

Write the program for the flowchart shown in PBASIC.


