How do I combine my lightSensor program and my joystick button program as one, so that when I press a button on the joystick, the sensor would come on and do what it is program to do, and when I press the button agian it will shut off. Moreoever, I would want to be able to drive the robot around as well and be able to use the other motors attached to it. Iam a rookie programmer and this is my first time working with the sensors. Thank you if you can help me.

Sun Mar 25, 2012 8:11 pm

magicode

Moderator

Joined: Tue Sep 14, 2010 9:19 pmPosts: 496

Re: How do I activate a lightSensor with a joystick button

Can you provide a little more detail on exactly what you want the code to do? Also, have you already tried any code? If so, post it and we can work on it from there.

I meant to say colorSensor sorry I want the RGB color sensor to be activated and run its assigned program when I press a button on the joystick

Mon Mar 26, 2012 2:49 pm

Soulbinder9

Rookie

Joined: Sun Mar 25, 2012 7:59 pmPosts: 7

Re: How do I activate a lightSensor with a joystick button

magicode wrote:

Can you provide a little more detail on exactly what you want the code to do? Also, have you already tried any code? If so, post it and we can work on it from there.

hello

Tue Mar 27, 2012 1:30 am

magicode

Moderator

Joined: Tue Sep 14, 2010 9:19 pmPosts: 496

Re: How do I activate a lightSensor with a joystick button

So if I'm understanding you correctly, you want to be able to keep the functionality that you have with your program now, but also have the light sensor code execute at the same time. I think that multitasking would be the easiest solution here, though there are other ways to do it.

Code:

task colorSensorTask(){ //do something //if there is a while loop without any wait1Msec commands, use EndTimeSlice(); somewhere in the loop. //The reasoning for this is to let the other tasks have time to run}

Last edited by magicode on Wed Mar 28, 2012 12:57 am, edited 1 time in total.

Tue Mar 27, 2012 3:02 am

Soulbinder9

Rookie

Joined: Sun Mar 25, 2012 7:59 pmPosts: 7

Re: How do I activate a lightSensor with a joystick button

Iam really need of help because I need to get this done before a deadline we have a competition and im like the only commited programmer. So that program you wrote on the forum that would tell the robot to start the color sensor when a button is pressed and turn it off when the button is pressed agian, can I just add that to my already written joystick program or do I have to do more complicated procedure. I will put this message on the forums agian.

Tue Mar 27, 2012 11:57 pm

magicode

Moderator

Joined: Tue Sep 14, 2010 9:19 pmPosts: 496

Re: How do I activate a lightSensor with a joystick button

I didn't know that you wanted the task to stop once you pressed the button again. That changes the program a little:

Code:

task colorSensorTask(){ //do something //if there is a while loop without any wait1Msec commands, use EndTimeSlice(); somewhere in the loop. //The reasoning for this is to let the other tasks have time to run}

I have not tested this or the previous code as I do not have access ROBOTC or a robot to test it on at the moment. The logic should work, but I can't guarantee anything. I just used this to demonstrate how to go about solving the problem.

_________________sudo rm -rf /

Wed Mar 28, 2012 1:03 am

Soulbinder9

Rookie

Joined: Sun Mar 25, 2012 7:59 pmPosts: 7

Re: How do I activate a lightSensor with a joystick button

I see what you mean just alittle, but I need to know where do I add my joystick program to? and another question you could answer if you want, but I cant find the ColorSensor on the try me on the NXT or under the view option, Iam using a RGB colorSensor and the only two colors I need to distinguish is red and blue. I need a program, that will allow a motor to go, when the colorSensor senses a Blue color or value, and for the motor to turn of when there is a Red color or value. Also I need it where I press a button the program, which I wrote for the ColorSensor will activate, but at the same time Iam able to drive my robot and use the other controls on the joystick. Thank you

Wed Mar 28, 2012 1:10 am

magicode

Moderator

Joined: Tue Sep 14, 2010 9:19 pmPosts: 496

Re: How do I activate a lightSensor with a joystick button

You would put your joystick program in the main while loop, and the code for the color sensor inside the colorSensorTask. As I said, I do not have ROBOTC in front of me, so I cannot help you with the sample programs.

_________________sudo rm -rf /

Wed Mar 28, 2012 1:30 am

Soulbinder9

Rookie

Joined: Sun Mar 25, 2012 7:59 pmPosts: 7

Re: How do I activate a lightSensor with a joystick button

Lol I understand its ok, and I need a simple colorSensor program? The sample on on RobotC is hard to understand, can you decode it for me.

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