Quote:
|
Originally Posted by stephenthe1
can you look at this and tell me if you see any errors.
Code:
//the encoder is at 50 resolution
//the arm motor is attatched to pwm_02
//the encoder is attatched to rc_dig_in06
unsigned int encoder;
if (p2_sw_trig == 1)
pwm_02 = 220;
if (rc_dig_in06 == 1)
encoder = encoder + 1;
if (encoder == 11)
pwm_02 = 128;
|
You only want to increment the encoder variable when rc_dig_in06 goes from 0-1 or from 1-0 (pick one). So you need to keep track of the previous value and the current value, then increment only when when it changes.