Documentation > nControl > API Reference
SBrick Tile
nControl™ 2021.0
SBrick tiles allow to pilot SBrick controllers* in generic applications.
*Note that the use of SBrick controllers requires an SBrick license or nControl™ subscription.
Introduction
SBrick tiles allows you to communicate with SBrick controllers; it provides easy access to your SBrick. When you click to tile it will execute the mouse click event script but you normally interface with the controller using the other tiles: up-down tiles, on-off tiles or generic tiles.
It's intended for generic SBrick applications, for example controlling a carousel or Ferris wheel. Use a train control tile to control a LEGO® train equipped with an SBrick.
Event Scripts
SBrick tiles support the following event scripts:
  • Activate tile event: is executed when the tile is activated by switching to simulation of operational mode.
  • Deactivate tile event: is executed when the tile is deactivated by switching to design of configuration mode.
  • Mouse click event: is executed when the user clicks on the tile.
  • API Functions
    Tile Specific Functions
    nSBrickTile.setPortAngle(port, angle)
    Sets the angle of a PF servo motor.
    • port: specifies the SBrick port to which the servo motor is connected. The supported value are: nConst.SB_PORT_1, nConst.SB_PORT_2, nConst.SB_PORT_3 and nConst.SB_PORT_4.
    • angle: specifies the angle of the servo motor. The angle is an integer value between -90 and 90. Positive values are clockwise angles, negative values are counterclockwise angles.
    nSBrickTile.setPortPower(port, power, scale = 255)
    Sets the power of a PF motor
    • port: specifies the SBrick port to which the motor is connected. The supported value are: nConst.SB_PORT_1, nConst.SB_PORT_2, nConst.SB_PORT_3 and nConst.SB_PORT_4.
    • power: specifies the power of the PF motor. The power is an integer value between -255 and 255. Positive values define clockwise rotation while negative values define counterclockwise rotation.
    • scale: an optional argument that defines the power scale. For example, by using scale = 100 the maximal motor power is defined by 100 instead of the default value of 255.
    Inherited from nTile
    nSBrickTile.clearScreen()
    Clear all the text in the console window.
    nSBrickTile.getTile(label)
    Returns the tile object specified by label. If there is no tile with the specified label, the function returns a None value.
    nSBrickTile.print(text)
    Prints text in the console window. If the console window it not yet visible, printing text will make it visible.
    nSBrickTile.showConsole(mode)
    Shows (mode = True) or hides (mode = False) the console window.
    nSBrickTile.sleep(duration)
    Stops the execution of the script for the the given number of seconds. Note that duration can be a floating point number, e.g. to suspend the script for half a seconds use self.sleep(0.5).
    nSBrickTile.timestamp()
    Returns the number of seconds that passed since nControl™ was launched. It returns a floating point value with the highest possible time resolution supported by your system. The difference between two time stamps provides the number of seconds elapsed between those two events.
    nSBrickTile.localVars
    Base property to which you can add local variables that retain their value after the event script finishes. For example self.localVars.myVar = 5 adds a new property myVar to self.localVars and gives it the value 5. The localVars property is local to the current tile meaning that each tile has its own independent localVars property.
    nSBrickTile.globalVars
    Base property to which you can add global variables that retain their value after the event script finishes. For example self.globalVars.myVar = 5 adds a new property myVar to self.globalVars and gives it the value 5. The globalVars property is global to nControl meaning that all tiles use the same globalVars property. As such globalVars can be used to exchange information between the tiles.