Vex Light Sensor Detector

So I am trying to build a small object detector using a light sensor with an LED pointing at it so when an object passes between them the light dims and the sensor reaches a threshold. Then some LED lights go on. This would need to be in a while loop to keep in running. Every time time I try to use it get errors like crazy.

I don’t know much about coding and this is rather confusing to me. I keep getting errors dealing with the brackets and such.

Thanks for any help given

Please post code samples inside

 blocks.

Terry

What errors are you getting?

Usually errors relating to brackets. Like it says there is no macthing brackets but there is one.

Prove it! Post your code for all the world to see. :slight_smile:

#pragma config(Sensor, in1,    lite,           sensorReflection)
#pragma config(Sensor, dgtl1,  Mlight,         sensorLEDtoVCC)
#pragma config(Sensor, dgtl2,  red,            sensorNone)
#pragma config(Sensor, dgtl3,  red2,           sensorNone)
#pragma config(Sensor, dgtl4,  green,          sensorNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
sensorValue[dgtl11] = 0;
	while{true}
		
	sensorValue[in1] > threshold;
		
		sensorValue[red] = 0;
		
		wait10Msec
		
		sensorValue[red2]
    
		sensorValue[green]
}

Here are the errors

File “C:\Users\Student.C105-10\Downloads\wrong.c” compiled on Nov 24 2014 09:18:39
Warning:Substituting similar variable ‘SensorValue’ for ‘sensorValue’. Check spelling and letter case.
Error:Missing ‘(’ before ‘{’
Warning:’;’ expected before ‘}’. Automatically inserted by compiler
Warning:Meaningless statement – no code generated
Warning:Substituting similar variable ‘SensorValue’ for ‘sensorValue’. Check spelling and letter case.
Error:Undefined variable ‘threshold’. ‘short’ assumed.
Warning:Meaningless statement – no code generated
Warning:Substituting similar variable ‘SensorValue’ for ‘sensorValue’. Check spelling and letter case.
Warning:Symbol ‘wait10Msec’ is ‘deprecated’ definition. There may be alternate symbol with equivalent functionality.
Error:Internal Compiler: Unexpected use of proc ‘wait10Msec’ in an expression
Error:Procedure ‘wait10Msec’ is invalid syntax at this point
Warning:Missing ‘;’ has been automatically inserted by compiler
Warning:Meaningless statement – no code generated
Warning:Substituting similar variable ‘SensorValue’ for ‘sensorValue’. Check spelling and letter case.
Warning:Missing ‘;’ has been automatically inserted by compiler
Warning:Meaningless statement – no code generated
Warning:Substituting similar variable ‘SensorValue’ for ‘sensorValue’. Check spelling and letter case.
Warning:’;’ expected before ‘}’. Automatically inserted by compiler
Warning:Meaningless statement – no code generated

I am at a loss with coding and I don’t have time to do all the fixing myself. Thanks to anyone who helps.

a few things…

The while loop declaration is incorrect.

See the example here.
http://www.robotc.net/wiki/Tutorials/Arduino_Projects/Additional_Info/Loops


while{true}

should be like this to loop around this section forever:


while(true)
{
     /// rest of code goes here


}  

Next, you use a conditional check as a statement… I am not exactly sure what you are trying to do. You can set a sensor to a specific value but you can’t tell the computer to make a value greater than another.


sensorValue[in1] > threshold;

That line should be within an if or while statement itself… Notice the brackets for when the condition trips, I go do this.


if(sensorValue[in1] > threshold)
{
     // some code that knows what I want to do when the sensor trips
}

if statements explained here:
http://www.robotc.net/wiki/Control_Structures

Next the wait is a function call and needs an argument to wait a specific number of milliseconds. You also forgot the semicolon so the compiler kept on going to the next line jamming all the text together as one line.

[

](http://www.robotc.net/wiki/VEX2_Functions_Timing)

Thank you. I am trying to make a ciggarette disposal that flashes lights to reduced ciggarette littler. So that is why I need the code to always be running.