ROBOTC.net forums
http://robotc.net/forums/

Help with Light Sensors.
http://robotc.net/forums/viewtopic.php?f=11&t=6967
Page 1 of 1

Author:  ACucco [ Tue Oct 15, 2013 10:29 am ]
Post subject:  Help with Light Sensors.

In my PLTW class we are working on Marble sorters. What we need to have it do is sense the type of marble (Wood, plastic, and Aluminum) I need the light sensor to detect what marble is infont of it and move the catching tray to the correct position.

I need to have a range of variables for each of the SensorValue constructs

When using the debugging menu I found that the lightsensor returns these values,
Plastic 325 - 340
Wood 415-420
Aluminum 380-390

How would I set up the construct so the tray goes to the correct spot for each.
Move to position one if the value is between 325-340
Move to position two if the value is between 415-420
Move to position three if the value is between 380-390

Author:  Ernest3.14 [ Tue Oct 15, 2013 8:29 pm ]
Post subject:  Re: Help with Light Sensors.

Use an "if... else if... else"-chain. http://www.learncpp.com/cpp-tutorial/52-if-statements/

Author:  ACucco [ Mon Oct 21, 2013 10:07 am ]
Post subject:  Re: Help with Light Sensors.

I understand how to use if else if statements, I need to know how to use ranges for the variables

Author:  CARBOT [ Mon Oct 21, 2013 12:41 pm ]
Post subject:  Re: Help with Light Sensors.

You could do this in a while loop...

IF((sensor>324)&&(sensor<341))
{move to plastic position}

IF((sensor>379)&&(sensor<391))
{move to aluminum position}

IF((sensor>414)&&(sensor<421))
{move to wood position}

Good luck, reply back with what you actually used.

Author:  Ernest3.14 [ Mon Oct 21, 2013 5:40 pm ]
Post subject:  Re: Help with Light Sensors.

It would be better to use an if-else if-else chain instead of a bunch of if's, just as good practice. It is also more optimal, since the loop will only have to do an average of 2 checks each time, instead of 3 checks. That's a 33% improvement.

Author:  CARBOT [ Fri Oct 25, 2013 12:42 pm ]
Post subject:  Re: Help with Light Sensors.

Would Ernest3.14 be so kind as to post pseudocode on how 3 non adjacent regions could be decided with two IF/ELSE statements.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/