Cortex: PLTW: POE - 3.1.4 Flashlight controlled by light sensor

My student is having trouble with the programming to control the flashlight by the light sensor. In the debugger window, we can see the light sensor reading properly, and we can manually control the flashlight. When we try to run the PLTW suggested code, it will not work. Here is the PLTW provided code:

while(1 ==1)
{
if(SensorValue(lightSensor)>700)
{
turnFlashlightOn(flashlight,127);
}
if(SensorValue(lightSensor)<=700)
{
turnFlashlightOff(flashlight);
}
}

I just went back and went back and looked at my code for that assignment when I was in POE (I am in AE now). I remember I had issues with that particular assignment. The turnFlashlightOn command did not seem to work for me. I ended up having to treat it like a motor and set the “power” to -127 to turn it on. The off command seems to work just fine, it is just the on command that has issues. Let me know if you have any other issues or questions.

3 Likes