dSwitch with RobotC and Lejos

In this post, we just want to cover how to use the dSwitch with two languages: RobotC and Lejos.  To use the dSwitch in NXT-G, see our website for the block.

Robot C:  To use the dSwitch in RobotC, you can simply use the motor block commands.  dSwitch user Steve Munk pointed out that to bring the dSwitch to “off” in RobotC, power to the motor block has to be set to “-1”.  The code to stop should look something like this:

motor[motorA] = -1; //turn dSwitch off
motor[motorA] = 0; //keep dSwitch off

Lejos: The code for using the dSwitch was developed by Juan Antonio Brena Moral.  He pass on the following code:

public class DSwitchTest {

* @param args
public static void main(String[] args) {

DSwitch ds = new DSwitch(MotorPort.A);
try {Thread.sleep(2000);} catch (Exception e) {}



Leave a reply