Go to Post Don't let my students know I skimmed that blog and didn't read it thoroughly. - rlance [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 28-11-2012, 11:30
Kazroid Kazroid is offline
hopeless promgrammer
AKA: Brian Kasner
FTC #5264 (ILITE Blue Chips)
Team Role: Programmer
 
Join Date: Oct 2012
Rookie Year: 2012
Location: Haymarket
Posts: 3
Kazroid is an unknown quantity at this point
Programming ordeal

Hello fellow FTCers.

My name is Brian, new to FTC, this site, and robotics and general.

My team is 5264, ILITE Blue Chips, from Haymarket.

I am one of our team's programmers, and I have a slight problem, and was hoping someone could help.

How do i set a light sensor to activate a LED light? For example, let's say I have a ligth sensor and 2 LED lights, one red, the other blue. When the sensor picks up anything >20, I want the red light to shine. then the sensor reads <20, I want the blue sensor to go off.
How could I program this in ROBOTC?

(Note: this isn't the exact scenario I'm in, but it's very similar)
__________________
Simply The Greatest
  #2   Spotlight this post!  
Unread 28-11-2012, 23:42
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Programming ordeal

Within main() you'd have something like this:
Code:
while(robot is running) {
    if(sensor value > 20) {
        turn red on;
        turn blue off;
    } else {
        turn red off;
        turn blue on;
    }
}
if you don't want the loop to end, you can make it while(true). Configure your light sensor with the Motors and Sensors dialog (I can't remember exactly where it is in the GUI off the top of my head, but it's there), and you can read its value with the SensorValue() function.

Turning red and blue on and off depends on the interface with the light; if it's the same as the standard NXT lamps, set the motor value corresponding to the port (eg. motor[motorA]) to 0 to turn it off, and to any other value up to 100 to turn it on at a given intensity (sign doesn't matter; the intensity at 100 is the same as at -100).
  #3   Spotlight this post!  
Unread 29-11-2012, 15:23
Kazroid Kazroid is offline
hopeless promgrammer
AKA: Brian Kasner
FTC #5264 (ILITE Blue Chips)
Team Role: Programmer
 
Join Date: Oct 2012
Rookie Year: 2012
Location: Haymarket
Posts: 3
Kazroid is an unknown quantity at this point
Re: Programming ordeal

The plan slightly changed, now it's only one LED light. What i plan is when I press the button, the light will go on got weighted rings, and if I press the button and the button is unweighted, the light will not go on (maybe flash, not sure)

would this work?

Quote:
task main()
{
while(true) {
if(sensorvalue[bucketlight] > 5) {
turn red on;
}
else
{
turn red off;
}
}


}
(i know a margin of > 5 is very small, but it's the best i got)
__________________
Simply The Greatest

Last edited by Kazroid : 30-11-2012 at 11:03.
  #4   Spotlight this post!  
Unread 30-11-2012, 23:48
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Programming ordeal

"turn red on" and "turn red off" aren't actual commands; you have to determine what the interface between the NXT and the LED is. If it's the same as a lamp, you control it like this:
Code:
motor[motorA] = 100; // Turn port A lamp on
motor[motorA] = 0; // turn port A lamp off
Also, the code you have will respond to sensor changes, but will ignore controller input. To learn how to interact with game controllers, look at the FTC example programs provided with RobotC.
__________________
I code stuff.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 02:31.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi