# If - then statements

Good Evening,

I am trying to define a value (Y') based on an initial value (Y)...

Y' Calculations

If Y = 326, then 326 = Y'

If Y < 326, then ((326-Y)+326)=Y'

If Y > 326, then (326-(Y-326))=Y'

If anybody could assist me in translating that into arduino code i would great appreciate it :)

## Comment viewing options

good call, thanks guys

Looking at this more closely, I noticed Y'(Y) is actually a continuous linear function, evaluating to Y'=(652-Y) at every point.

y_accent = 652 - y

Even for values below 0 or values above 652.

when i enter that code and try to upload it, i receive this error...

In function 'void loop()':

error: 'IF' was not declared in this scop

Hmm, maybe the Arduino IDE is touchy abouts caps and spaces, try:

if (Y==326)
{
Y'=326;
}

else if (Y<326)
{
Y'=((326-Y)+326);
}

else
{
Y'=(326-(Y-326));
}

Also: the apostrophe (or single quote) might be illegal as part of a variable name. You'd better give it a name that only consists of alphabet characters. Underscores are probably OK. Periods perhaps. Anything else will probably bork. Only use numbers in varnames after an alphabetic char.

Disclaimer: I do not actually speak C (Arduino or otherwise).

awesome, thanks telefox

Try this for size:

IF(Y==326)
{
Y'=326;
}

ELSE IF(Y<326)
{
Y'=((326-Y)+326);
}

ELSE
{
Y'=(326-(Y-326));
}

The "==" operator tests if two things are equal, whereas just "=" makes the two things equal =)

FYI http://arduino.cc/ is a nice reference for Arduino-flavoured C programming.

nvm