All computer systems have something called API (Application Programming Interface), which defines how to “interface” to the device. For example, Windows operating system has an API that coders use to store a files onto the PC.
Tip: The API Quick Reference is a handy page to use down the road.
This lesson assumes you have already gone through the setup and introduction lessons.
There are several advanced drawing functions to give you better control over the display or LED-matrix. They are covered in the Drawing lesson.
Outputs whatever it is given to the screen. On the BrainPad Pulse, the output shows on the screen and scrolls up with every new Print(), like a text window.
In the case of BrainPad Tick, the text will scroll across the LEDs. If the text being printed is a single character, then that one character will just show on the LEDs.
This one should explain itself. Wait() forces the BrainPad to “wait” for some time. The following code will Print 1 and then “wait” one second, then Print 2, then “wait” another second, and finally Print 3.
Print(1); Wait(1); Print(2); Wait(1); Print(3);
Print(1) Wait(1) Print(2) Wait(1) Print(3)
Fractions are used to wait for less than one second. Wait(1/2) or Wait(0.5) are used to wait for half a second, for example.
In() & Out()
All physical elements surrounding the brain (the processor) are controlled using In() or Out() functions. This is how computers work and detailed in the Input -> Process -> Output lesson.
The OutIn() function handles special cases that Out and In can not do on their own. This is for advance uses only and rarely need, so feel free to skip this lesson.
The OutIn() is needed to handle busses, like I2C. Unlike Out() and In(), it uses bytes instead of doubles. It accepts 2 byte arrays, one to send and one to receive. The out (write) count is determined by the length/size of the out array. The in (read) count e is determined by the in array length/size.
OutIn() also allows the user to either write or read. The undesired argument can be set to null.
// Write Only OutIn(i2c, myarray, null); // Read Only OutIn(i2c, null, myarray)
# Write only OutIn(i2c, myarray, null) # Read Only OutIn(i2c, null, myarray)
See how OutIn() is used in the I2C Bus lesson.
Learn more about the use of In() and Out() in the Input -> Process -> Output lesson.
As a human communicating with another human, can we think of a standard API for communication? How do we handle trust and security? Think of layers of control in a financial institution or in the military. How do we ensure commands flow properly?
What about you as a person? What senses feed info into your brain? And what actions are you taking? Can you think of priority commands that take over non-priority? What happened when you are very hungry and you hold a piece of very hot chicken? Does your brain continue to command your muscles to eat that piece of chicken, or will it will stop you? What about controlling your heartrate voluntarily? Or holding your breath? Why do you think questions like these help you understand why coding is important?