Now you might wonder what I would want this for. Say that I'm making a pong game, and I'm using an RCX rotation sensor to control the tray. I make the tray display with an X value equal to the rotation sensor, so that you can control the tray just like those old Atari controllers. If it goes too far to the left, I can simply reset the rotation sensor, and it will stop at the left edge of the screen. This requires very few lines of code. As for doing this on the right side of the screen, it would be very handy to be able to keep the rotation sensor from reading anything above 76. Here's what code I have so far:
Code: Select all
task main()
{
SetSensor(IN_2, SENSOR_ROTATION);
while(true)
{
RectOut(SENSOR_2, 0, 24, 4); Wait(30); //Display the tray with the X
ClearScreen(); //value equal to the rotation sensor.
if(SENSOR_2 <= 0)
{
ClearSensor(IN_2); //If it goes too far to the left, it resets the sensor to zero
} //so that the tray can't go too far to the left.
}
}