Any

Variables

 

In programming, a variable is a labeled section of memory that holds a specific data value. Once we create this variable, the data contained can be referenced multiple times. When you use a variable as a parameter of a function, the value of that variable is passed to the function. In our example, we create the "timer1" variable and set it to 1000. Later, when we set the parameter of our wait1Msec command as "timer1" the effective result is that the wait timer is set to 1000.

#pragma

 

Before you use a motor, you must configure the NXT to access it. This brings us to our next rule:

Waddle Bot Unit 1

Waddle Bot Unit 1 Lesson 1

Functions Without Parameters

-- eraseDisplay --
  • Function Syntax: eraseDisplay()

Function Libraries

Some functions require more than one parameter. The way you can how many parameters is needed is by looking at the documentation. The first source of information is the Function Library within RobotC. This will generate when you compile a program. RobotC will also hide some of the more advanced functions from this list. To see them you need to change your menu level.

Elements of a Function

Primitive Data Types

 

At the most general level, everything in a program can be separated into two general groups: Commands and Data. The main difference between these groups is the ability to store information. Commands can only perform actions while data is information that can be acted upon.

The main data types that we will work with are:

Comments and White Space

 

RobotC is a free-form programming language. This means that when you write a program, multiple spaces, tabs, and line returns are ignored by the NXT. This allows us to use these ignored structures to format our program and make it easier to read. If wanted, we could put all of our commands on one line. Here is what the above example program would look like if we did:

Task [string]label { } Introduction

When you open a new RobotC program, you start with a blank slate, with no instructions. The NXT/RobotC was designed with a number of rules that force us to write or programs in a certain way. Our first rule of RobotC is:

1. NXT actions shall reside within tasks.

Pages