Wheel IDE

Online demo »

Hub motor

Powered Up Hub motor example

This example shows how to select the Hub device with two different types of motors.

The Hub has only two ports, in this example one motor with a tacho counter is selected and a basic motor which has no tacho counter.

Code

#project "Powered Up Hub motor example"

#include "lib/modules/standard.whl"
#include "lib/modules/device.whl"
#include "lib/modules/motor.whl"
#include "lib/modules/poweredUp.whl"

#display "Hub"

proc main()
    ; Select the Powered Up mode in the simulator:
    selectDevice(DEVICE_POWERED_UP)

    ; Select the Hub device:
    poweredUpSetDevice(LAYER_1, POWERED_UP_HUB)

    ; Select the motor types:
    motorSetType(OUTPUT_A, POWERED_UP_DEVICE_BOOST_TACHO_MOTOR)
    motorSetType(OUTPUT_B, POWERED_UP_DEVICE_BASIC_MOTOR)

    ; Set the motor speed and brake...
    motorLayerSetSpeed(LAYER_1, OUTPUT_A, 50)
    motorLayerSetSpeed(LAYER_1, OUTPUT_B, 75)
    motorLayerSetBrake(LAYER_1, OUTPUT_A, MOTOR_BRAKE)

    ; Reset output A on layer 1
    motorLayerReset(LAYER_1, OUTPUT_A)
    ; Move the motor to 720 degrees
    motorLayerMoveTo(LAYER_1, OUTPUT_A, 720)

    ; Set the speed of output B and turn the motor on...
    motorLayerSetSpeed(LAYER_1, OUTPUT_B, 25)
    motorLayerOn(LAYER_1, OUTPUT_B)

    halt()
end