DUE Built-in Functions

Built-in Functions

Every language ships with several built-in functions, sometimes referred to as core library or standard library. These functions provide important functionality. The ones found in DUE Script are specific for handling hardware.

Prerequisite

This lesson assumes you’re already familiar with DUE Script basics.

Intro

Built-in functions, sometimes referred to as API (Application Programming Interface), are functions that are pre-made and found internally in the system.


Print()

The Print() function outputs whatever argument it is given to the output window.

Print("Hello")
Print(5)

Println() work the same way except it adds a new line.

LcdConfig() is used to modify the behavior of Print() and Println() causing them to print on the screen, just like they prints to the output.

This image has an empty alt attribute; its file name is BrainPadPulse_API_1.gif

Note that LcdConfig() allows for adding external displays to the BrainPad. More on that in future lessons.


Wait()

Just as you may be thinking, Wait() forces the BrainPad to pause for some time. The following code will output 1 and then pause for one second, then it outputs 2 and pauses for another second, and finally ends with output of 3.

Print(1)
Wait(1000)
Print(2)
Wait(1000)
Print(3)

System Built-ins

There are some functions that are built-in as part of the programming languages we’re using. While languages may have different definitions of those functions, they provide a similar outcome. DUE Scripts built-in are called core library. They are documented on the DUE Script corelib page found the DUE Link website.

We will document Rnd() here, a random number generator. Other lessons will be using/detailing other APIs as well.

x = Rnd(100)
Print(x)

The argument in the above example (100) tells the function to give us a random number that is no more than 100. How do you generate a random number that is between 30 and 50?

x = Rnd(50-30)+30
Print(x)

Can you use those random numbers to plot points or shapes on the screen at random locations? Just keep the shapes within the screen by limiting the random number to a max of the screen size. Don’t know how to draw yet? Well, that is next!

LcdClear(0)
@loop
x = Rnd(127)
y = Rnd(64)
LcdPixel(1, x, y)
LcdShow()
Goto loop

What’s Next?

You now know enough coding and you deserve to start with some fun topics. The next step is to learn about drawing.

BrainStorm

Do animals and humans have built in functions at birth? Why do some newborn animals get up as soon as they are born and start following their mom? Why does a parent is willing to risk their life to protect their children? Is this something they learned or it is built in our brains?

Content Licensing
Newsletter

Twitter Feed
Hot off the press!