Hey, sorry about making a billion threads about this, but I’m trying to get your attention as quickly as possible since we don’t have much time left. the code for my sensor does not work properly and I don’t know where the problem(s) is(are). It is a metal detector that will sense a metal strip in a rope that is used in a winch system to lift the ringers. The metal strips will be placed in certain locations so that when the rope/metal strip passes the metal detector the motor will stop. If i want to keep going I simply press the trigger and it goes to the next level of the SPIDER. This is the code. Any help would be fantastic. If you have questions, please ask them so I can help you help me! THANKS!
In User_Routines.c:
void Default_Routine(void)
{
int now; //for mapping rc_dig_in04 to ON or OFF (sensor)
int last; //for mapping rc_dig_in04 to ON or OFF (sensor)
int now2; //for mapping p3_sw_trig to ON or OFF (reset p3_y)
int last2; //for mapping p3_sw_trig to ON or OFF (reset p3_y)
int now3; //for mapping p3_sw_aux1 to ON or OFF (reset counter)
int last3; //for mapping p3_sw_aux1 to ON or OFF (reset counter)
int now4; //for mapping p3_sw_aux2 to ON or OFF (reset CAMERA)
int last4; //for mapping p3_sw_aux2 to ON or OFF (reset CAMERA)
last = now;
now = rc_dig_in04;
last2 = now2;
now2 = p3_sw_trig;
last3 = now3;
now3 = p3_sw_aux1;
blah blah blah…joystick mappings… THEN
CODE THAT RELATES TO SENSOR/FORKLIFT
if((now3 == 1) && (last3 == 0)) //p3_sw_aux1 sets counter to 0 in case forklift needs to be reset.
{
count = 0;
}
if((now2 == 1) && (last2 == 0)) //p3_sw_trig sets joystick 3 y-axis to forklift motor. Use after each level.
{
pwm03 = p3_y;
}
if((pwm03 < 125) || (pwm03 > 129)) //if py_3 is being used (forklift going up or down)
{
if((now == 1) && (last == 0)) //If sensor, which connects to Dig In/Out port 4, sends a signal...
{
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;
}
switch(count) //for sensor module
{
case 1: //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.
Relay2_green = 1;
Relay2_red = 0;
printf("count = 1");
break;
case 2:
Relay2_green = 1;
Relay2_red = 0;
pwm03 != p3_y;
pwm03 = 127; //Motor stops when it reaches 1st level of rack.
printf("count = 2");
break;
case 3:
Relay2_green = 1;
Relay2_red = 0;
pwm03 != p3_y;
pwm03 = 127; //Motor stops when it reaches 2nd level.
printf("count = 3");
break;
case 4:
Relay2_green = 1;
Relay2_red = 1;
pwm03 != p3_y;
pwm03 = 127; //Motor stops when it reaches top level.
printf("count = 4");
break;
case 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.
printf("count = 5");
break;
case 6:
Relay2_green = 0;
Relay2_red = 1;
pwm03 != p3_y;
pwm03 = 127; //Motor stops when it retreats to 2nd level.
printf("count = 6");
break;
case 7:
Relay2_green = 0;
Relay2_red = 1;
pwm03 != p3_y;
pwm03 = 127; //Motor stops when it retreats to 1st level.
printf("count = 7");
break;
case 8:
Relay2_green = 0;
Relay2_red = 0;
pwm03 != p3_y;
pwm03 = 127; //Motor stops when it retreats to ground level.
printf("count = 8 but will reset now.");
count = 0;
break;
}
}
Thanks so much for your help.