View Single Post
  #15   Spotlight this post!  
Unread 16-02-2004, 17:10
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Odd counter problems

Quote:
Originally Posted by rbayer
A few things I saw after glancing at it:
Code:
if (armcounter = 15) //will raise arm.
   pwm06=0;
else 
   armcounter++;
   pwm06=255;
sould be
Code:
if (armcounter == 15) //will raise arm.
   pwm06=0;
else {
   armcounter++;
   pwm06=255; 
}
It is VERY rare that you'll actually want to use a single = in an if, so watch out for that, and also be careful with your curly braces.

That said, I believe the code in its original form should have printf'd 15 over and over and over. Was it doing that, or just not printing anything?
remember that you need to add the curly braces, not just change the equals sign to a double-equals. w/o the braces, the code is equivalent to this:

Code:
if (armcounter == 15) //will raise arm.
   pwm06=0;
else {
   armcounter++; 
}

pwm06=255;
note how pwm06 will always end up as 255, no matter what the value is.

you said that the "motors weren't stopping" - of course they aren't: 0 is full reverse, 255 is full forward. if you want a motor to stop, set the PWM to 127.
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)