Code: #pragma config(CircuitBoardType, typeCktBoardUNO) #pragma config(PluginCircuitBoard, typeShieldParallaxBoeBot) #pragma config(Sensor, anlg0, leftLight, sensorReflection) #pragma config(Sensor, anlg1, rightLight, sensorReflection) #pragma config(Sensor, dgtl5, led1, sensorDigitalOut) #pragma config(Sensor, dgtl6, led2, sensorDigitalOut) #pragma config(Motor, servo_10, leftServo, tmotorServoContinuousRotation, openLoop, IOPins, dgtl10, None) #pragma config(Motor, servo_11, rightServo, tmotorServoContinuousRotation, openLoop, reversed, IOPins, dgtl11, None) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main() { while(true) { int factor = 120; //This value worked for us however you might want to change it for your robot/flashlight intensity. int shadeDiff = ((SensorValue[rightLight] * factor) / (SensorValue[leftLight] + SensorValue[rightLight]) - (factor / 2)) * 2; motor[leftServo] = 20 + shadeDiff; motor[rightServo] = 20 - shadeDiff; //If the loop cycles too quickly, we get calculation errors. Therefore we regulate the speed by waiting a bit. wait1Msec(10); } }
task main() { while(true) //repeat indefinitely { //turn led1 on SensorValue[led1] = true;
//turn led2 off SensorValue[led2] = false;
//wait 1 second wait1Msec(300);
//turn the led1 off SensorValue[led1] = false;
//turn led2 on SensorValue[led2] = true;
//wait 1 second wait1Msec(300); } }
|