View unanswered posts | View active topics It is currently Fri Jun 22, 2018 5:23 am

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
Help with Light Sensors.
Author Message
Rookie

Joined: Tue Oct 15, 2013 10:21 am
Posts: 2
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

Tue Oct 15, 2013 10:29 am
Professor

Joined: Sat May 18, 2013 1:24 pm
Posts: 271
Location: Olympia, WA
Re: Help with Light Sensors.
Use an "if... else if... else"-chain. http://www.learncpp.com/cpp-tutorial/52-if-statements/

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

Tue Oct 15, 2013 8:29 pm
Rookie

Joined: Tue Oct 15, 2013 10:21 am
Posts: 2
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

Mon Oct 21, 2013 10:07 am
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
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.

Mon Oct 21, 2013 12:41 pm
Professor

Joined: Sat May 18, 2013 1:24 pm
Posts: 271
Location: Olympia, WA
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.

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

Mon Oct 21, 2013 5:40 pm
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
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.

Fri Oct 25, 2013 12:42 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 6 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning