Skip to main content

Modules

Modules are the part of JARU that talks to the world: the screen, the sound, the buttons, the board's pins, the network and the files. Each one gathers its functions, properties and constants under a name, which you write in front: Display.open, GPIO.write, Math.PI.

Overview of JARU modules for graphics, hardware, communication, data, and system features

How to use them​

A program says which modules it uses with use, one per line or several separated by commas:

use Math, GPIO
use Display

println(Math.sqrt(16)) // 4
  • A name that isn't a module doesn't compile: use Nothing gives the error Module not found.
  • If you use a module without its use, the program compiles, but stops when it reaches that line with ERR_MODULE_NOT_FOUND (Module 'Math' not found or not imported.).
  • use is for JARU's modules; your project's files are brought in with import. The difference is in Programs in several files.

The modules are the same on Windows and on every board. What changes from one platform to another is told by each page in its "Platforms" section.

Some functions don't belong to any module and need no use, such as println, pause, clock or random: they're in the Standard library. The methods of strings, lists and maps are in Strings and in Lists, maps and arrays.

The modules​

Graphics and games​

ModuleWhat for
DisplayOpening the screen or the window, its size and its background, and the game's pace
DrawDrawing points, lines, rectangles, circles, text, images and tilemaps
BitmapLoading BMP images and working with them
SpriteSprites with animation, collisions and physics
GridMap2D grids: tilemaps, collisions with the map and pathfinding
SceneThe scene: its sprites, the camera, the physics and the map
SoundSynthesised sounds, PCM samples and music

Input​

ModuleWhat for
InputThe keyboard, the buttons and the gamepad, as game actions

Hardware​

ModuleWhat for
GPIOInput and output pins, PWM and interrupts
I2CSensors and other devices connected over I2C
LEDStrips and matrices of WS2812 colour LEDs
PowerPutting the board to sleep to save power, and waking it up

Communications​

ModuleWhat for
MQTTPublishing and receiving MQTT messages
HttpHTTP requests to APIs and web services

Data and files​

ModuleWhat for
FileFiles and folders, in the flash, on the SD card or on the PC
BytesByte blocks for binary data
JSONReading and writing JSON

System​

ModuleWhat for
TimerCalling a function after some time, once or every so often
MathMathematical functions and constants
GCThe garbage collector, which frees the memory that's no longer used