View Single Post
  #14   Spotlight this post!  
Unread 09-12-2004, 19:33
stephenthe1 stephenthe1 is offline
Registered User
#1008
 
Join Date: Dec 2004
Location: Ohio
Posts: 113
stephenthe1 is on a distinguished road
Re: encoder vs. motor

so like with this code

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 = 0;
	if (p1_sw_trig == 1)
{
	if (encoder <= 10)
{
    pwm_02 = 254;
	if (rc_dig_in06  == 1)
{
	encoder = encoder + 1;
	if (encoder > 10)
{
	pwm_02 = 127;
}
}
}
}
I assigned a value of zero to encoder, however, every time the code is reread (every 30 milliseconds or something?), the value for encoder will be set back to zero, making its function useless. wish there was a way to make it so the thing didn't reread the code every amount of time, but rather go over it once and remember everything, and do everything from there. that's the way it is in most programming languages isn't it. anyway, do you see what I mean? or will it only assign the value of zero to it once and then when it reanalyzes the code, it will use the last assigned value. I don't think it works that way though.