GetSwitch

Reads the current value of the NXT switch / touch sensor

Contents

Syntax

switch = GetSwitch(port)

switch = GetSwitch(port, handle)

Description

switch = GetSwitch(port) returns the current switch value switch of the NXT switch / touch sensor. The measurement value switch represents the pressing mode of the switch / touch sensor. true is returned if the switch / touch sensor is being pressed and false if it is being released. The given port number specifies the connection port. The value port can be addressed by the symbolic constants SENSOR_1, SENSOR_2, SENSOR_3 and SENSOR_4 analog to the labeling on the NXT Brick.

The last optional argument can be a valid NXT handle. If none is specified, the default handle will be used (call COM_SetDefaultNXT to set one).

For more complex settings the function NXT_GetInputValues can be used.

Example

   OpenSwitch(SENSOR_4);
   switchState = GetSwitch(SENSOR_4);
   CloseSensor(SENSOR_4);

See also

NXT_GetInputValues, OpenSwitch, CloseSensor, SENSOR_1, SENSOR_2, SENSOR_3, SENSOR_4,

Signature