//*!!Sensor, S1, SENSOR1, sensorLightInactive, , !!*// //*!! !!*// //*!!Start automatically generated configuration code. !!*// const tSensors SENSOR1 = (tSensors) S1; //sensorLightInactive //*!!!!*// //*!!CLICK to edit 'wizard' created sensor & motor configuration. !!*// /* Program for ROBOARM II. This is the NXT part. The NXT brick responds to six different light signals sent by the RCX. The signals are received by a light sensor (sensormode inactive) on port 1. Then it turns on one of motors, depending on the received signal. Please go to http://www.freewebs.com/laurens200/ for more robots and a video of this one. This program is written using RobotC. (http://www.robotc.net) */ int bit2 = 0; int bit3 = 0; int bit4 = 0; task main() { while(true) { while(SensorValue[S1] < 50){} // Do nothing until light flash. wait1Msec(170); if(SensorValue[S1] > 50) { bit2 =1;}// bit2 is 1 or 0 wait1Msec(100); if(SensorValue[S1] > 50) { bit3 =1;} // bit3 is 1 or 0 wait1Msec(100); if(SensorValue[S1] > 50) { bit4 =1;} // bit4 is 1 or 0 /////////////////// /* The following statements turn on one of motors, depending on the received signal.*/ /////////////////// if(bit2 ==0 && bit3 ==0 && bit4 ==1)// signal 1001 { motor[motorC] = 100; wait1Msec(500); while(SensorValue[S1] < 50){} //wait for next signal, then stop the motor. motor[motorC] = 0; } /////////////////// /////////////////// /////////////////// if(bit2 ==1 && bit3 ==0 && bit4 ==0)// signal 1100 { motor[motorC] = -100; wait1Msec(500); while(SensorValue[S1] < 50){} //wait for next signal, then stop the motor. motor[motorC] = 0; } /////////////////// /////////////////// /////////////////// if(bit2 ==1 && bit3 ==1 && bit4 ==0)// signal 1110 { motor[motorB] = -100; wait1Msec(1000); while(SensorValue[S1] < 50){} //wait for next signal, then stop the motor. motor[motorB] = 0; } /////////////////// /////////////////// /////////////////// if(bit2 ==1 && bit3 ==1 && bit4 ==1)// signal 1111 { motor[motorB] = 100; wait1Msec(500); while(SensorValue[S1] < 50){} //wait for next signal, then stop the motor. motor[motorB] = 0; } /////////////////// /////////////////// /////////////////// if(bit2 ==0 && bit3 ==1 && bit4 ==1)// signal 1011 { motor[motorA] = -100; wait1Msec(500); while(SensorValue[S1] < 50){} //wait for next signal, then stop the motor. motor[motorA] = 0; } /////////////////// /////////////////// /////////////////// if(bit2 ==1 && bit3 ==0 && bit4 ==1)// signal 1101 { motor[motorA] = 100; wait1Msec(500); while(SensorValue[S1] < 50){} //wait for next signal, then stop the motor. motor[motorA] = 0; } /////////////////// /////////////////// /////////////////// bit2 = 0; // reset the values. bit3 = 0; bit4 = 0; wait1Msec(500); // do nothing for half a second to prevent errors. } }