View Single Post
  #11   Spotlight this post!  
Unread 15-02-2006, 10:42
aaeamdar's Avatar
aaeamdar aaeamdar is offline
Post-A-Holic
AKA: Paul Dennis
FRC #1719 (The Umbrella Corp)
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Baltimore, MD
Posts: 231
aaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant futureaaeamdar has a brilliant future
Re: A few simple programming questions;

Quote:
Originally Posted by Inverted
Sorry I'm not being as big of a help as I should be, but I'm in the middle of homework and just answering the questions where the solution is on the top of my head.


You don't need (p3_sw_trig == 0) after the else, it's already implied. Also, (this may be wrong because I haven't written code like this in 2 years) I think you only need one = when referring to the value of the button, not ==.


The PWM cable from the Spike goes into one of the Relay outputs on the robot controller. Then you just map which buttons you want to control which relays and you're good. Not sure if you know how to or not, but send me a PM if you want to know how to have one button control the in/out of a piston and such (like if you want a solenoid to act like a festo).

Technically, it's not implied. The code within the segment following the else executes no matter what if the first IF and all IF ELSEs after it fail.

Another correction: == is an operator that returns a one or a zero based on whether the LHS (left hand side) is equal to the RHS. the = operator sets the LHS (which has to be a valid LHS, aka a variable) equal to the RHS. It returns the set value. C will let you get away with this:

if (x = 5)
stuff();

It assumes, "Oh, I know what he wants to do. He wants me to set x to five and then check to see if x or not." AKA, this will not cause a compile time error, whereas in Java it will.

Note that the == returns a 1 or a 0, not any boolean value, for those used to Java or other such. The other comparisons (>, < , <=, >=, etc) work the same way.

Neat but terrible shorthand (don't do this):

x += x < 100;

Which does? I throw it out there.

Paul Dennis