View Single Post
  #19   Spotlight this post!  
Unread 06-01-2007, 15:57
Noah Kleinberg Noah Kleinberg is offline
Registered User
FRC #0395 (2TrainRobotics)
Team Role: Driver
 
Join Date: Jan 2006
Rookie Year: 2006
Location: New York
Posts: 196
Noah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to beholdNoah Kleinberg is a splendid one to behold
Send a message via AIM to Noah Kleinberg
Re: Why it works with an underscore?

Quote:
Originally Posted by Generalx5 View Post
It compiles now, but its still not responding to the changes in the sensors. If one of the sensors changed signals and this setting is defined as setting_2 below, it does not change the settings for the solenoids.

This is how im using the codes:


#define Setting_1 solenoid1 = 1;solenoid2 = 0; solenoid3 = 1;solenoid4 = 0; solenoid5 = 0; solenoid6 = 1
#define Setting_2 solenoid1 = 0;solenoid2 = 1; solenoid3 = 0;solenoid4 = 1; solenoid5 = 1; solenoid6 = 0



if ((Senor1 = 1) && (Sensor2 = 1) && (Sensor3 = 1) && (Sensor4 = 1) && (Sensor5 = 1))
{
Setting_1;
}
if ((Senor1 = 1) && (Sensor2 = 1) && (Sensor3 = 1) && (Sensor4 = 1) && (Sensor5 = 0))
{
Setting_2;
}

Your problem here is that you're using "=" instead of "==" inside your if statement. "=" sets a variable's value, while "==" tests for equality.

(x==y) returns a true or false value based on the equality of x and y, but (x=y), like you have here, returns whatever y is equal to, which in this case is 1 (or 0 for one of them) (0 represents false, and anything besides 0 represents true). Therefore you're always entering the first if statement because all of the conditions always return "1", whereas the second one is never reached because "sensor5=0" always returns 0.

Hope this was helpful.