Quote:
Originally Posted by Generalx5
Is it possible to define something and have a set of commands built into it?
Something like this?
#define Setting_1 ((solenoid1 = 1) && (Solenoid2 = 0) && (solenoid3 = 1) && (solenoid4 = 0) && (solenoid5 = 0) && (solenoid6 = 0));
will this allow me to do....
if (Sensors_are_online);
{
Setting_1
}
basically if the sensor receives a signal, it would turn on setting_1 which is to turn solenoid 1 and solenoid 3 on.
|
Yes, #define basically does a find & replace. However, it is a good practice to not have a semicolon at the end of a macro, that way, when you use the macro, it has a semicolon at the end of the line and keeps you from wondering whether you are missing any semicolons.
By the way, you don't need a semicolon after the if (Sensors_are_online) statement.
In general, any sort of construct that uses curly braces does not have a semicolon for itself. Rather, the individual statements within the braces have semicolons at the end of them.