LEGO® Powered Up simple code block guide

This is the simple code block guide for the LEGO® Powered Up app. It is created to provide help with Powered Up programming, it contains information about the code blocks used in the Free Play area of the app.
Latest update: 01/29/2020
App version used: 3.0.0

Usage

This is the simplified version of the code block guide. Click here for the extended version with all the information, column filtering, search function etc.

In this version each block can be identified with the icon, the number of the visible columns depends on your screen size / resolution. To show all data corresponding to a block click on the Green + icon next to the block’s image, that will show/hide the additional information.

Glossary

Simple motor – a Powered Up motor that only has power regulation, like the 45303 Simple Medium Linear Motor
Tacho motor – a Powered Up motor that has an internal encoder and has speed and position regulation like the 88008 Medium Linear Motor or the L / XL motors.
Slider interface – one of the controller interfaces in the Free Code area of the Powered Up app with 2 sliders and 3 buttons
Race Car interface – one of the controller intarfaces in the Free Code area of the Powered Up app with 1 joystick and 4 buttons
Composite Block – a block that contains one or more program sequences

Disclaimer – This guide is partially based on a document received from LEGO® Customer Service, additional information and examples were added based on the Powered Up app and my experience.

Block ImageBlock CategoryBlock NameDescription (official / my notes)ExampleExample (code)
Flow BlocksStartStarts the execution of the attached sequence when the block is clicked or when the program starts.Starts the sequence that sets the motor power on port A to 50
Flow BlocksStartOnTrueStarts the execution of the attached sequence when the condition is true.If Slider 1's position is not 0 then sets the light intensity on port D to 100%
Flow BlocksStartOnEdgeStarts the execution of the attached sequence when the condition switches from false to true.If Slider 1's position is changed from 0 then play the car start sound
Flow BlocksEventStartStarts the execution of the attached sequence when the flag number is triggered.The Start sequence begins first, sets the light intensity on port D to 100% then triggers the "Flag 1" sequence that sets the motor power on port A to 50.
Flow BlocksEventTriggerTriggers flag number.The Start sequence begins first, sets the light intensity on port D to 100% then triggers the "Flag 1" sequence that sets the motor power on port A to 50.
Flow BlocksWaitForTimeWait for time (in seconds).After the sequence is started the timer waits for 2 seconds before setting the motor power on port A to 50
Flow BlocksWaitForTrueWait for the condition to become true.The sequence sets the light intensity on port D to 0%, then waits for the slider to be moved, once it is moved it plays the car start sound
Flow BlocksCountLoopLoop enclosed sequence for number of times.The Hub's LED light is set to red and then off 3 times - this makes the LED blink quickly in red 3 times
Flow BlocksWhileLoopLopp enclosed sequence while condition is true.Plays the engine revving sound until the slider is moved
Flow BlocksLoopForeverLoop enclosed sequence forever.The most frequently used and most important loop - required for every "square" that needs to run constantly. Here Slider 1 sets the speed of motor on port A, it needs to loop to adjust the speed constantly according to the position of the slider.
Flow BlocksIfSwitchIf condition is true then execute top sequence, else execute bottom sequence.If the slider is below 50 then the LED on the hub is red, over 50 it turns green. Enclosed in a loop for constant monitoring of the slider position.
Flow BlocksForkJoinExecute both sequences at the same time, and wait for both sequences to complete before executing next block.Motor A runs for 2 seconds, motor B runs for 5 seconds but the car sound is played only when both motors stop.
Flow BlocksInterruptOthersStops all other program sequences and continues with execution of the attached sequence.Slider 1 controls the power of motor A, once the wheel button is pressed the slider stops working and the car brake sound is played.
Flow BlocksEndStops the execution of all sequences running on the current canvas.
If used in the top most program, this will terminate the program.
If used in a Model Block, then the Model Block is terminated, but the program containing the Model Block will continue execution.
Wheel button acts as an emergency stop, once it is pressed all other sequences are stopped therefore the slider will stop controlling the speed of the motor.
SensorsTriggerOnColorTriggers when the color measured by the Sensor is equal to color.
Boost Sensor only
If the sensor attached to port C detects red then the sound is played
SensorsWaitForColorWait for the color measured by the Sensor to be equal to color.
Boost sensor only
The Hub's LED is turned off first, if the sensor attached to port C detects red then the Hub's LED is also switched to red
SensorsColorSensorGet current color measured by the Sensor.
Boost sensor only
The Hub's sensor is set to the color what the sensor attached to port C detects
SensorsTriggerOnDistancelessThanTriggers when the distance measured by the Sensor is less than distance.
Boost sensor only
If the sensor detects something at distance 5 then the sound is played
SensorsWaitForDistancelessThanWait for the distance measured by the Sensor to be less than distance.
Boost sensor only.
The Hub's LED is turned off first, if the sensor attached to port C detects something in distance '5' then the Hub's LED is also switched to red
SensorsVisionProximitySensor AddressablePortGet current distance measured by the Sensor.
Boost sensor only
If something gets closer to the sensor than distance '5' then the sound is played
SensorsVisionReflectionSensor AddressablePortGet current ambient light level measured by the Sensor.
Boost sensor only
If the something covers the light sensor (value becomes greater than 2) then the sound is played
SensorsTriggerOnOrientationTriggers when the Hub Orientation is equal to Hub Orientation.
Boost hub only
If the Hub's orientation becomes horizontal then the Hub's LED color switched to red
SensorsWaitForOrientationWait for the Hub orientation to be equal to Hub orientation.
Boost hub only
If the Hub's orientation becomes horizontal then the Hub's LED color switched to red
SensorsDriveBaseTiltGetOrientation AddressablePortGet current Hub orientation.
Boost hub only
The Hub's orientation is stored in variable "a" and can be used as an input in other sequences
SensorsDriverbaseTiltGetAngleX AddressablePortGet current Hub tilt angle on the X axis (-90 .90).
Boost Hub only
The Hub's tilt angle X is displayed on the slider controller screen
SensorsDriverbaseTiltGetAngleY AddressablePortGet current Hub tilt angle on the Y axis (-90 .90).
Boost Hub only
The Hub's tilt angle Y is displayed on the slider controller screen
SensorsOrientationAngleCaptures data with the Boost hub and the Technic hub as well. Boost hub provides only X and Y data, Technic hub provides X, Y and Z dataIf the Hub moves (X value changes from 0) then a sound is played
SensorsDrivebaseTiltConfigure OrientationAddressablePortSupposed to set the tilt orientation of Boost hub but it does not override the value detected - more tests needed.
SensorsAccelerometerCaptures data with the Boost hub and the Technic hub as well, exact information is unconfirmed
SensorsDistanceSensor AddressablePortWeDo sensor only
SensorsTiltSensorXAddressablePortWeDo sensor only
SensorsTiltSensorYAddressablePortWeDo sensor only
SensorsAccelerometerXUses the X axis tilt position of the smart device (left-right). 0 is the central position.The App-Controlled Batmobile can be controlled with this configuration, the smart device's orientation drives it forward-backward and turns it as well
SensorsAccelerometerYUses the y axis tilt position of the smart device (forward-backward). 0 is around 30 degrees with the device screen facing towards you.The App-Controlled Batmobile can be controlled with this configuration, the smart device's orientation drives it forward-backward and turns it as well
MotorsMotorPowerSets power to the motor - Positive numbers rotates clockwise and negative rotates counter clockwise - Power value can be between -100 and 100Slider 1 sets the power of motor on port A, it's in a loop adjust the speed constantly according to the position of the slider.
MotorsContinuousMedium MotorControlSets power to the motor attached to the selected port and runs until the program runs without the need of a loop - Positive numbers rotates clockwise and negative rotates counter clockwise (Between -100 and 100)Slider 1 sets the speed of motor on port A. No need to put in a loop as the block with a rounded end runs continously.
MotorsMotorFloatRemoves power from the motorTacho motor on port A runs at speed 50 for 2 seconds, then power is cut from the motor and it can be rotated freely
MotorsContinuousMediumMotor ControlSpeedSteeringSets power to the motors attached to the selected ports and runs until the program runs without the need of a loop. First value sets the speed, second value defines steering (changing the speed of the motors to steer the vehicle), third value defines if both motors run in the same or opposite directions.The App-Controlled Batmobile can be controlled with this configuration, the smart device's orientation drives it forward-backward and turns it as well
MotorsMotorBrakeStops the motorTacho motor on port A runs at speed 50 for 2 seconds, then power is cut from the motor but the motor "brake" is on, difficult to turn
MotorsTachoMotorGetSpeedReads the speed value of the motor attached to the specified portSpeed of Tacho motor on port A is displayed on the Slider controller interface's left widget
MotorsTachoMotorSpeedRun tacho motor on defined port with speed (-100..100)Slider 1 sets the speed of Tacho motor on port A, it's in a loop adjust the speed constantly according to the position of the slider.
MotorsTachoMotorSpeedDurationRun tacho motor on defined port with speed (-100..100) for duration (in seconds)Tacho motor on port A runs for 5 seconds with speed 50, then stops and actively holds position
MotorsTachoMotorGetPositionReads the position of the tacho motor. Position is relative, 0 is the position where the motor was turned on.Position of Tacho motor on port A is displayed on the Slider controller interface's left widget
MotorsTachoMotorSpeedPositionTurns the tacho motor on defined port with defined speed (0..100) to the defined position (-9999..9999 in degrees)Position of Tacho motor on port A is set to 45, it turns with speed 50
MotorsTachoMotorPresetPositionSets the current position of the tacho motor on defined port to the defined value (-9999..9999 in degrees)Tacho motor's current position is set to 0 - position of the motor is relative, 0 is the "turn on" value, this can be resetted with this command to the current position
MotorsTachoMotorHoldStops and holds the tacho motor on defined port Tacho motor on port A runs for 5 seconds with speed 50, then stops and actively holds position
MotorsTachoMotorMaxPowerSets max power of the tacho motor on defined port (0..100)Sets the maximum power of the Tacho motor on port A to 25, then the speed is controlled with Slider 1 on the controller interface. With this change the motor only runs at 25%.
MotorsTachoMotorAccelerationTimeSets the acceleration duration (in seconds) of the tacho motor on defined port The acceleration and deceleration time of the Tacho motor on port A is set to 0.1, this makes the reaction to the slider movement very fast.
MotorsTachoMotorDecelerationTimeSets the deceleration duration (in seconds) of the tacho motor on defined port The acceleration and deceleration time of the Tacho motor on port A is set to 0.1, this makes the reaction to the slider movement very fast.
MotorsSynchroMotorPowerSets independently the power (-100..100) of a pair of motors on the defined ports (AB or CD)The power of the motors attached to port AB is set to 50
MotorsSynchroTachoMotorSpeedSets independently the speed (-100..100) of a pair of tacho motors on the defined ports (AB or CD)The speed of the Tacho motors attached to port AB is set to 50. This command works for the Boost internal motors as well.
MotorsSynchroTachoMotor SpeedDurationSets independently the speed (-100..100) of a pair of tacho motors on the defined ports (AB or CD) for duration (in seconds)The speed of the Tacho motors attached to port AB is set to 50 and they run for 5 seconds. This command works for the Boost internal motors as well.
MotorsSynchroTachoMotor SpeedPositionSets the the position (-9999..9999) of a pair of tacho motors on the defined ports (AB or CD) with speed independently set (-100..100)The Tacho motors attached to port AB are both turned to 85 degrees position with the speed of 50. This command works for the Boost internal motors as well.
MotorsSynchroTachoMotor SpeedSteeringSets the speed (-100..100) of a pair of tacho motors on the defined ports (AB or CD) with the steering direction (-100..100) defining a tank steering style behavior. 0 sets equal power to both outputs, 50 only powers one motor and 100 powers the motors in opposite directions. Positive-negative value for steering defines the direction.The Tacho motors attached to port AB tank-steered to 49% with the speed of 50. This command works for the Boost internal motors as well.
MotorsSynchroTachoMotor SpeedSteeringDurationSets the speed (-100..100) of a pair of tacho motors on the defined ports (AB or CD) with the steering direction (-100..100) defining a tank steering style behavior. The motors are running for the defined duration (in sconds). 0 sets equal power to both outputs, 50 only powers one motor and 100 powers the motors in opposite directions. Positive-negative value for steering defines the direction.The Tacho motors attached to port AB tank-steered to 50% with the speed of 50 for 5 seconds. This command works for the Boost internal motors as well.
MotorsSynchroTachoMotor SpeedSteeringPositionSets the speed (-100..100) of a pair of tacho motors on the defined ports (AB or CD) with the steering direction (-100..100) defining a tank steering style behavior. The motors are running until the defined degree of rotation is reached (-9999..9999 in degrees). 0 sets equal power to both outputs, 50 only powers one motor and 100 powers the motors in opposite directions. Positive-negative value for steering defines the direction.The Tacho motors attached to port AB tank-steered to the direction of 100% (meaning the 2 motors are running in opposite direction) with the speed of 50, and they both turn only 90 degrees. This command works for the Boost internal motors as well.
Custom Controllerwidget-reporter-block-37Returns the current value of the AccelratorWidget 1Run motor connected to port A with a given speed based on the value of the slider
Custom Controllerwidget-reporter-block-38Returns the current value of the AccelratorWidget 2Similar to widget-reporter-block-37
Custom Controllerwidget-reporter-block-39Starts the execution of the programming strip when the wheel button is pressed.When the wheel button on the controller screen is pressed the following sound will be executed
Custom Controllerwidget-reporter-block-40Starts the execution of the programming strip when the traffic light button is pressed.Similar to widget-reporter-block-39
Custom Controllerwidget-reporter-block-41Starts the execution of the programming strip when the road button is pressed.Similar to widget-reporter-block-39
Custom Controllerwidget-reporter-block-42Returns the current value of the SpeedoMeter Widget 1
Usually used to trigger the execution of other programming strips based on its value
If the value of the widget is below 50 then the LED on the hub is red, over 50 it turns green. Enclosed in a loop for constant monitoring of the slider position.
Custom Controllerwidget-reporter-block-43Returns the current value of the SpeedoMeter Widget 2
Usually used to trigger the execution of other programming strips based on its value
Similar to widget-reporter-block-42
Custom Controllerwidget-instruction-block-38Slider Widget 1 that can go from -100 to 100Changes the start position of Slider 1, in this case it starts with the value 50
Custom Controllerwidget-instruction-block-39Slider Widget 2 that can go from -100 to 100Similar to widget-reporter-block-43
Custom Controllerwidget-instruction-block-40Boolean Widget that can trigger the StartOnWheelChange block - Triggers the widget when the condition is trueThe Wheel widget is triggered when the slider is moved (value is changed from 0) - the Wheel widget needs to be also defined like in the example of widget-reporter-block-39
Custom Controllerwidget-instruction-block-41Boolean Widget that can trigger the StartOnTrafficlightChange block - Triggers the widget when the condition is trueSimilar to widget-instruction-block-40
Custom Controllerwidget-instruction-block-42Boolean Widget that can trigger theS tartOnRoadChange block - Triggers the widget when the condition is trueSimilar to widget-instruction-block-40
Custom Controllerwidget-instruction-block-43Widget that can display a numeric value on the controller screen (left)The widget display a numeric value on the Controller interface, in this case it displays the speed of the Tacho motor on port A
Custom Controllerwidget-instruction-block-44Widget that can display a numeric value on the controller screen (right)Similar to widget-instruction-block-43
Custom Controllerwidget-reporter-block-55Starts the execution of the programming strip when the wheel button is pressed.Similar to widget-reporter-block-39
Custom Controllerwidget-reporter-block-56Starts the execution of the programming strip when the tools button is pressed.Similar to widget-reporter-block-39
Custom Controllerwidget-reporter-block-57Starts the execution of the programming strip when the flags button is pressed.Similar to widget-reporter-block-39
Custom Controllerwidget-reporter-block-58Starts the execution of the programming strip when the red button is pressed.Similar to widget-reporter-block-39
Custom Controllerwidget-reporter-block-59aReturns the current X (horizontal) value of the joystick (-100..100)
Custom Controllerwidget-reporter-block-59bReturns the current Y (vertical) value of the joystick (-100..100)The value is used to change the speed of the simple motor attached to port A
Custom Controllerwidget-reporter-block-59cReturns the relative distance of the joystick from 0, positive/negative value depends on the forward/backward direction (-100..100).The value is used to change the speed of the simple motor attached to port A
Custom Controllerwidget-reporter-block-59dReturns the steering angle value of the joystick (-90..90)
Custom Controllerwidget-reporter-block-60Assumption - should return the value of the speed meter widget (-100..100) but always stays 0
Custom Controllerwidget-reporter-block-62Returns the value of the turbo widget (0..100)
Custom Controllerwidget-instruction-block-55Triggers wheel widget when the condition is trueSimilar to widget-instruction-block-40
Custom Controllerwidget-instruction-block-56Triggers tools widget when the condition is trueSimilar to widget-instruction-block-40
Custom Controllerwidget-instruction-block-57Triggers flag widget when the condition is trueSimilar to widget-instruction-block-40
Custom Controllerwidget-instruction-block-58Triggers red button widget when the condition is trueSimilar to widget-instruction-block-40
Custom Controllerwidget-instruction-block-59aJoystick X (horizontal) axis Widget that can go from -100 to 100
Custom Controllerwidget-instruction-block-59bJoystick Y (vertical) axis Widget that can go from -100 to 100
Custom Controllerwidget-instruction-block-59cJoystick X (horizontal) and Y (vertical) axis Widget that can go from -100 to 100
Custom Controllerwidget-instruction-block-60Sets the value of the speed meter widgetSimilar to widget-instruction-block-43
Custom Controllerwidget-instruction-block-62Sets the value of the turbo widgetSimilar to widget-instruction-block-43
Light & SoundLightPercentageSets the power of the attached LED on the defined port to % (0..100)If Slider 1's position is not 0 then sets the light intensity on port D to 100%
Light & SoundSetHubLightIndexColor AddressablePortSet the Hub LED to show color - Works on Boost/City/Technic hubsThe Hub's LED light is set to red and then off 3 times - this makes the LED blink quickly in red 3 times
Light & SoundSetHubLightRGBColor AddressablePortSets the Hub LED to show color based on the RGB intensity defined (Red, Green and Blue value in %). Works on Boost/City/Technic hubsSets the Hub's LED light to Red - 0%, Green - 50% and Blue: 100%
Light & SoundVisionSensorSetColor AddressablePortSets the color of the Sensor LED.
Boost sensor only
Sets the color of the Boost sensor attached to port A to blue
Light & SoundPlaySoundHousePlay the selected sound from the House sound libraryPlays the first sound effect from the House sound library
Light & SoundPlaySoundWhistlePlay the selected sound from the Whistle sound librarySimilar to PlaySoundHouse
Light & SoundPlaySoundTrainPlay the selected sound from the Train sound librarySimilar to PlaySoundHouse
Light & SoundPlaySoundCarPlay the selected sound from the Car sound librarySimilar to PlaySoundHouse
Light & SoundPlaySoundPlanePlay the selected sound from the Plane sound librarySimilar to PlaySoundHouse
Light & SoundPlaySoundDogPlay the selected sound from the Dog sound librarySimilar to PlaySoundHouse
Light & SoundPlaySoundCatPlay the selected sound from the Cat sound librarySimilar to PlaySoundHouse
Light & SoundPlaySoundFartPlay the selected sound from the Fart sound librarySimilar to PlaySoundHouse
Light & SoundPlaySoundHornPlay the selected sound from the Horn sound librarySimilar to PlaySoundHouse
Light & SoundPlaySoundCrowdPlay the selected sound from the Crowd sound librarySimilar to PlaySoundHouse
Light & SoundPlaySoundRobotPlay the selected sound from the Robot sound librarySimilar to PlaySoundHouse
Light & SoundPlaySoundTargetPlay the selected sound from the Target sound librarySimilar to PlaySoundHouse
Data OperationsLEGODeviceAddress AndPortSelectorSets the device and port to be used. Device number (1..4) is set on the connection screen (Bluetooth icon in top-left corner). Port can be either internal (connector icon) or external.Sets the speed of the normal motor attached to port B of the second hub on the connection list. The speed is set to the value stored in the local variable a.
Data OperationsLocalVariableFetchReads the number stored in the local variable. Local variables are not shared between the main program and the composite blocks.Sets the speed of the normal motor attached to port B of the second hub on the connection list. The speed is set to the value stored in the local variable a.
Data OperationsLocalVariableStoreUpdates local variable to store number. Local variables are not shared between the main program and the composite blocks.Sets the value of the local variable a to 50.
Data OperationsGlobalVariableFetchReads the number stored in the global variable - Global variables are shared between the main program and the composite blocks.Similar to LocalVariableFetch, the difference is that this variable is shared between the main program and the composite blocks.
Data OperationsGlobalVariableStoreUpdate global variable to store number - Global variables are shared between the main program and the composite blocks.Similar to LocalVariableStore, the difference is that this variable is shared between the main program and the composite blocks.
Data OperationsInvertInputInverts the input value (+/-)The App-Controlled Batmobile can be controlled with this configuration, the smart device's orientation drives it forward-backward and turns it as well. The InvertInput block is used to invert one of tilt values of the smart device to match the turning direction of the vehicle
Data OperationsRandomOperatorReturns a random number between number and number (both numbers included in the range).The value of the local variable b is a random number between 1 and 10
Data OperationsEqualOperatorReturns whether number is equal to number.Plays the engine revving sound until the slider's value equals to 0
Data OperationsLessThanOperatorReturns whether number is less than number.Usage principle is similar to EqualOperator
Data OperationsGreaterThanOperatorReturns whether number is greater than number.Usage principle is similar to EqualOperator
Data OperationsNotEqualOperatorReturns whether number is not equal to number.Usage principle is similar to EqualOperator
Data OperationsAndOperatorReturns true if both operators are true, and false otherwise.Sound is triggered if both sliders are moved (their position is not equal to 0)
Data OperationsOrOperatorReturns true if either operand is true, and false otherwiseSound is triggered if one of the sliders is moved (position is not equal to 0)
Data OperationsPlusOperatorReturns the result of adding number to number.Usage principle is similar to EqualOperator
Data OperationsMinusOperatorReturns the result of number substracted with number.Usage principle is similar to EqualOperator
Data OperationsMultiplyOperatorReturns the result of number multiplied with number.Usage principle is similar to EqualOperator
Data OperationsDivisionOperatorReturns the reuslt of number divided by number.Usage principle is similar to EqualOperator
Data OperationsAdvancedMathSupports the following mathematical operations: Round to nearest, Round down, Round up, Absolute value, Squareroot, Squared, Sine, Cosine, Tangent, Arcsine, Arccosine and Arctangent, radians to degrees conversion.If the slider's position is below 50 in either direction (+/-) then the LED on the hub is red, over 50 it turns green. Advanced operator "Absolute value" is used to have the red range between -50 and 50. Enclosed in a loop for constant monitoring of the slider position.
Data OperationsAtan2Returns the result of the function {atan2} (y,x) or {arctan2} (y,x)
Data OperationsExponentReturns the result of raising number (first value) to the power of the exponent (second value).
Data OperationsMaxReturns the maximum value of number (first value) and number (second value).
Data OperationsMinReturns the minimum value of number (first value) and number (second value).
Data OperationsModuloReturns the remainder after divison of number (first value) by number (second value).
Composite BlockCreateCompositeBlockCreates a composite block that acts as a program inside our program and can be executed by its custom icon.
Composite BlockCompositeBlockFuelingPredefined Composite Block in the Race Car interface
Composite BlockCompositeBlockJoystickPredefined Composite Block in the Race Car interface
Composite BlockCompositeBlockCrashPredefined Composite Block in the Race Car interface
Advertisements

Comments are closed.