ROBOTC.net Blog  

ROBOTC News

Archive for the ‘Flashlight’ tag

Controlling the Brightness of the VEX Flashlight

without comments

VEX FlashlightThe VEX Flashlight is an awesome accessory that will let your robot “lighten up” any situation it’s in.

Cheesy puns aside, the VEX Flashlight contains four bright LED’s – useful for lighting up a dark environment, keeping constant light on an object or line the robot is tracking, or any number of other possible applications.

One of the limitations of the two-wire flashlight, though, is that its brightness cannot be controlled by the standard 3-wire MOTOR ports on the VEX PIC or VEX Cortex. In today’s post, we’ll overcome that limitation using one of the VEX Motor Controllers.

In the picture below, the VEX Flashlight is connected to MOTOR Port 2 on the Cortex using one of the VEX Motor Controllers. Also attached are a light sensor to measure the amount of light provided by the flash light in the ROBOTC Debugger, and a potentiometer to enable us to vary the amount of light.

In the sample program below, we use feedback from the potentiometer to control the brightness of the flashlight. The potentiometer provides values between 0 and 4095 on the Cortex, so we have to scale that down by a factor of 32 to stay within the range of values the Flashlight will accept (0 to 127). Note also, that in the configuration pragma statements, the flashlight is configured as a “reversed” motor; it actually accepts values ranging from 0 to -127. Reversing it allows us to give it more intuitive, positive values.

#pragma config(Sensor, in1,    light,               sensorReflection)
#pragma config(Sensor, in2,    potentiometer,       sensorPotentiometer)
#pragma config(Motor,  port2,           flashlight,    tmotorNormal, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
 while(true) //Loop Forever
 {
 //Set the power of the flashlight equal to a scaled value from the potentiometer
 motor[flashlight] = SensorValue[potentiometer]/32;
 //Divide by 32 on the Cortex, since the potentiometer values are 0 - 4095
 //Divide by 8 on the PIC, since the potentiometer values are 0 - 1023
 }

}

Check out this video of the brightness control in action:


YouTube Direct Link VEX Flashlight - Brightness Control

In case you want to try this out, but don’t have a potentiometer, here’s more sample code that just cycles through different brightness values, over and over. You can see that programming the VEX Flashlight works basically the same as programming a motor.

#pragma config(Sensor, in1,    light1,              sensorReflection)
#pragma config(Motor,  port2,           flashlight,    tmotorNormal, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
 //Loop Forever
 while(true)
 {
 //Turn off flashlight for 2 seconds
 motor[flashlight] = 0;
 wait1Msec(2000);

 //Turn on flashlight at 1/4 brightness for 2 seconds
 motor[flashlight] = 31;
 wait1Msec(2000);

 //Turn on flashlight at 1/2 brightness for 2 seconds
 motor[flashlight] = 63;
 wait1Msec(2000);

 //Turn on flashlight at 3/4 brightness for 2 seconds
 motor[flashlight] = 96;
 wait1Msec(2000);

 //Turn on flashlight at full brightness for 2 seconds
 motor[flashlight] = 127;
 wait1Msec(2000);
 }
}

Written by Jesse Flot

February 3rd, 2011 at 2:48 pm

Posted in Cortex,PIC,VEX

Tagged with , ,