View unanswered posts | View active topics It is currently Fri Jul 10, 2020 7:34 pm






Reply to topic  [ 4 posts ] 
Port Assigning 
Author Message
Rookie

Joined: Sat Nov 08, 2014 3:56 pm
Posts: 7
Post Port Assigning
In RobotC for EV3, how can I assign a color sensor to ports other than port 3 and can I have 3 sensors operating simultaneously?


Sat Nov 08, 2014 9:59 pm
Profile
Rookie

Joined: Sat Nov 08, 2014 3:56 pm
Posts: 7
Post Re: Port Assigning
Sorry, I meant 3 of the same sensors operating simultaneously.


Sat Nov 08, 2014 10:04 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: Port Assigning
Hi positronemitter,

It's not as hard as you might think! ROBOTC has a motor and sensor setup tool that allos you to do just that. First, ROBOTC must be set to "expert" mode. You can do that by selecting "expert" from the "Menu Level" sub menu from the "Window" entry:
Attachment:
Screenshot at 06-02-10.png
Screenshot at 06-02-10.png [ 9.21 KiB | Viewed 5062 times ]

This enables a couple of options that you normally won't need access to if you're just starting out.

Next, we'll go ahead and open the "Motor and Sensor Setup" utility from the "Robot" menu:
Attachment:
Screenshot at 06-03-52.png
Screenshot at 06-03-52.png [ 11.28 KiB | Viewed 5062 times ]


The utility will pop up on your screen. Fill it out like this example and click "Apply". When you do, the lines starting with "#pragma" will be put into your program:
Attachment:
Screenshot at 06-03-32.png
Screenshot at 06-03-32.png [ 29.72 KiB | Viewed 5062 times ]


You're good to go now. You can reference the sensors in a program like this:
Code:
#pragma config(Sensor, S1,     colour_1,       sensorEV3_Color, modeEV3Color_Ambient)
#pragma config(Sensor, S2,     colour_2,       sensorEV3_Color)
#pragma config(Sensor, S3,     colour_3,       sensorEV3_Color, modeEV3Color_Color)
#pragma config(Sensor, S4,     colour_4,       sensorEV3_Color)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
  while (true)
  {
    displayTextLine(2, "Sensor 1: %d", getColorAmbient(colour_1));
    displayTextLine(2, "Sensor 2: %d", getColorReflected(colour_1));
   
    // This is actually a number from 0 to 7:
    // colorNone    = 0,
    // colorBlack   = 1,
    // colorBlue    = 2,
    // colorGreen   = 3,
    // colorYellow  = 4,
    // colorRed     = 5,
    // colorWhite   = 6,
    // colorBrown   = 7
    displayTextLine(2, "Sensor 3: %d", getColorName(colour_1));
   
    displayTextLine(2, "Sensor 4: %d", getColorReflected(colour_1));
  }
}


= Xander


Attachments:
Screenshot at 06-03-32.png
Screenshot at 06-03-32.png [ 29.72 KiB | Viewed 5062 times ]

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]
Sun Nov 09, 2014 1:15 am
Profile WWW
Rookie

Joined: Sat Nov 08, 2014 3:56 pm
Posts: 7
Post Re: Port Assigning
Awesome. I'm going to give it a go. Thank you!


Sat Nov 15, 2014 11:16 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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

Search for:
Jump to:  
cron



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.