Device

The device library allows you to gather information about the devices connected to each of the hubs ports, as well as set the duty cycle of a device at a specific port.

Constants

  1. MOTOR_MEDIUM_ID=48
  2. MOTOR_LARGE_ID=49
  3. COLOR_SENSOR_ID=61
  4. DISTANCE_SENSOR_ID=62
  5. FORCE_SENSOR_ID=63

GetDataFromPort(integer port)

Returns

Array<integer>
Returns the raw LPF-2 data from the device connected to the provided port. The data is returned in an integer array of size 8

Parameters

  1. 1.integerport

    The port (ranging from A to F or 0 to 5) with the device to collect data from

Example

1 2 3 4 5 6 7 use Libraries.Robots.Spike.Device use Libraries.Robots.Spike.Port use Libraries.Containers.Array Device dv Port port Array<integer> raw_data_of_port_A raw_data_of_port_A = dv:GetDataFromPort(port:A)

GetIDOfPort(integer port)

Returns

integer
Returns the integer ID of the device at the provided port

Parameters

  1. 1.integerport

    The port (ranging from A to F or 0 to 5) with the device to get the ID of

Example

1 2 3 4 5 use Libraries.Robots.Spike.Device use Libraries.Robots.Spike.Port Device dv Port port integer port_A_device_ID = dv:GetIDOfPort(port:A)

GetDutyCycle(integer port)

Returns

integer
Returns the PWM, the duty cycle (from 0 to 10000) of the device at the provided port

Parameters

  1. 1.integerport

    The port (ranging from A to F or 0 to 5) with the device to get the duty cycle of

Example

1 2 3 4 5 use Libraries.Robots.Spike.Device use Libraries.Robots.Spike.Port Device dv Port port integer port_A_duty_cycle = dv:GetDutyCycle(port:A)

SetDutyCycle(integer port, integer duty_cycle)

Returns

None
Sets the duty cycle (PWM) of a device at the provided port. Duty cycle value can range from 0 to 10000.

Parameters

  1. 1.integerport

    The port (ranging from A to F or 0 to 5) with the device to set the duty cycle of

  2. 2.integerduty_cycle

    The integer value from 0 to 10000 to set the duty cycle of the device to

Example

1 2 3 4 5 use Libraries.Robots.Spike.Device use Libraries.Robots.Spike.Port Device dv Port port dv:SetDutyCycle(port:A, 5000)

IsPortReady(integer port)

Returns

boolean
Returns true if the device is ready for requests, false if not

Parameters

  1. 1.integerport

    The port (ranging from A to F or 0 to 5) with the device to check the ready state of

Example

1 2 3 4 5 6 7 8 9 10 11 12 use Libraries.Robots.Spike.Device use Libraries.Robots.Spike.Hub use Libraries.Robots.Spike.LightMatrix use Libraries.Robots.Spike.Port Port port Device dv Hub hb LightMatrix lights repeat until IsPortReady(port:A) hb:Sleep(1) end lights:Write("Device at Port A is READY!!!")