View Single Post
  #6   Spotlight this post!  
Unread 11-02-2007, 01:20
Ianuser Ianuser is offline
Registered User
FRC #0570
 
Join Date: Feb 2007
Location: new york
Posts: 64
Ianuser is an unknown quantity at this point
Re: How do I program this sensor?

This is what I have now:

Code:
void Default_Routine(void)
{
 	int count = 0;
	int now;
	int last;
	now = last;
	rc_dig_in04 = now;
blah blah blah..map joysticks..

Code:
 /***************
                  * Sensor Code *
                  ***************/
 
 	if((pwm03 < 125) || (pwm03 > 129))
 	{
 		if((now == 1) && (last == 0)) //If sensor, which connects to Dig In/Out port 4, goes off...
		{
			count++; //Number of times tape passes through the sensor.
			Switch1_LED = 1; //Switch01 goes on when the tape passes the sensor.
		}
		else
		{
			Switch1_LED = 0;
		}
	
	
		if(count == 8) 
		{
			Relay2_green = 0;
			Relay2_red = 0;
			pwm03 = 127; //Motor stops when it retreats to ground level.
			count = 0;
		}
		else if(count == 7) 
		{
			Relay2_green = 0;
			Relay2_red = 1;
			pwm03 = 127; //Motor stops when it retreats to 1st level.
		}
		else if(count == 6) 
		{
			Relay2_green = 0;
			Relay2_red = 1;
			pwm03 = 127; //Motor stops when it retreats to 2nd level.
		}
		else if(count == 5) 
		{
			Relay2_green = 0;
			Relay2_red = 1;
			//pwm03 does not equal 127 because it must pass the tape in order to go beneath the top level.
		}
		else if(count == 4)
		{
			Relay2_green = 1;
			Relay2_red = 1;
			pwm03 = 127; //Motor stops when it reaches top level.
		}
		else if(count == 3)
		{
			Relay2_green = 1;
			Relay2_red = 0;
			pwm03 = 127; //Motor stops when it reaches 2nd level.
		}
		else if(count == 2)
		{
			Relay2_green = 1;
			Relay2_red = 0;
			pwm03 = 127; //Motor stops when it reaches 1st level.
		}
		//if count == 1 then that just means that it passed through the first piece of tape which will be used to show that it is in full DOWN position.
	}
So I have yet to make the switch statement, but I made some changes. Do you understand yet what I am trying to do with the forklift Kevin? (Any other thoughts also) Thank you guys so much. You're saving my team of 5.