|
Re: how about this code.
Quote:
|
Originally Posted by stephenthe1
we tried to keep the motor speed down so the encoder will read each tick before the program refreshes. so the motor doesn't "beat" the program before it reads the encoder.
Code:
//the encoder is at 50 resolution
//the arm motor is attatched to pwm_02
//the encoder is attatched to rc_dig_in06
static unsigned int encoder;
static unsigned int pressedornot;
if (p1_sw_trig == 1)
{
if (encoder <= 10)
{
pwm_02 = 150;
if (rc_dig_in06 == 1)
{
encoder = encoder + 1;
if (encoder > 10)
{
pwm_02 = 127;
}
}
}
}
|
Stephen,
You can see I attempted to reformat your code to make it more readable. Now you can see how your code nests...
I agree with Mark. I'm not worried about you missing an encoder ping but rather that you will get multiple hits at one ping.
You should consider implementing a state machine. Do you have a mentor on your team (what team are you with anyway?) who can teach you what a state machine is?
__________________
Mike Betts
Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013
As easy as 355/113...
|