Skip to main content
SAM Script gives you a consistent API to control every SAM Labs hardware block. Connect a block by name, then call methods on the object it returns. The examples below show the full API for each block type in both JavaScript and Python.
All JavaScript connect calls are asynchronous — remember to use await inside an async function. Python calls are synchronous and can be used directly.

Blocks

The LED block lets you display any RGB color and control brightness. Use it for visual feedback, status indicators, or creative lighting effects.Connect: plug the LED block into your SAM hub or pair it over Bluetooth, then reference it by the name 'led'.
The button block registers when a user presses or releases its physical button. Use event callbacks to react in real time, or poll the current state when you need it.Connect: pair the button block and reference it by the name 'button'.
The DC motor block drives a continuous rotation motor. You can set its speed and direction independently, making it ideal for wheeled robots and conveyor-belt projects.Connect: pair the DC motor block and reference it by 'dcMotor' (JavaScript) or 'dc_motor' (Python).
The servo block moves to an exact angular position between 0° and 180°. Use it for robotic arms, steering mechanisms, or any project that needs controlled positional movement.Connect: pair the servo block and reference it by the name 'servo'.
The light sensor block reads the brightness of the surrounding environment. You can poll it for a single reading or register a callback that fires whenever the value changes.Connect: pair the light sensor block and reference it by 'lightSensor' (JavaScript) or 'light_sensor' (Python).
The buzzer block generates audio tones. You can specify a musical note name and duration, or supply a raw frequency in hertz for full control over the sound.Connect: pair the buzzer block and reference it by the name 'buzzer'.