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.
0 Comments
Leave a reply
You must be logged in to post a comment.
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.
You must be logged in to post a comment.
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.
This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.
Keeping this cookie enabled helps us to improve our website.
Please enable Strictly Necessary Cookies first so that we can save your preferences!
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
wait1Msec(100);
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);
ds.turnOn();
try {Thread.sleep(2000);} catch (Exception e) {}
ds.turnOff();
}
}