scottnanax.blogg.se

Robotc tutorials
Robotc tutorials












robotc tutorials

For the ultrasonic sensor, the value is distance, and for color, the value is the reflected light. For the touch sensor, there are only two values, 0 (not pressed) or 1 (pressed). For the first line here, you put the name of the sensor, in this case “touch” in the parenthesis, use an equality (=) or inequality (!=) sign, and a set a value. This tells the robot to go forward while the touch sensor is not pressed, the go back a little when it is pressed. In this tutorial, though, I will just be going over the while statement. These are the “While” and “If” statements. In order to program sensors, we need to learn two simple but very helpful statements.

robotc tutorials

You need these lines to have the sensors work. Click OK and the text should be at the top of your code. Now we dont want to type that every time, so to automatically insert it, go to Robot>Motors and Sensors Setup, and go to the sensor tab to fill in the sensor info. What’s this, you say? It is saying that the sensor is in sensor port 1, named “touch”, and it is a touch sensor.

robotc tutorials

#pragma config(Sensor, S1, touch, sensorTouch) Later models come with a color sensor that replaces light, but I prefer the light over color. The NXT has four types sensors that come with it: the ultrasonic sensor, the light sensor, the touch sensor, and the sound sensor. Sensors are the main part of the NXT, and are the items that the NXT is most useful for.














Robotc tutorials