A couple of simple language questions

Hi,

I downloaded the IDE about a week ago and wrote a small program that controls the cooling fan speed for a RF power amplifier. I was looking to enhance the program and while poking around the Arduino site the following three issues showed up:

  1. By accident, I found a page describing the difference between the “Processing” language and the “Arduino” language. What language am I programming in in the Arduino IDE? Whats the relationship between them and also with wiring?

  2. I declare a bunch of initialized variables at the beginning of loop(). For instance boolean runningFast = false; or keylineState = NOT_TRANSMITTING. Are each of these variables re-initialized every time through? Putting them at global scope, (say, just above loop()) seems a little drastic, just to prevent re-initialization. Putting them in setup() makes the code harder to understand.

  3. In the description of “Constants” in the language section on the web site there is a nice description of HIGH and LOW. But it doesn’t include their values. For a predicate like X != HIGH there’s no problem, but what about !HIGH or !LOW? Are HIGH and LOW aliases for boolean values?

Thanks in advance for any replies. They will help me get my feet an the ground with this new (to me) environment.

–Lenny W.

  1. By accident, I found a page describing the difference between the "Processing" language and the "Arduino" language. What language am I programming in in the Arduino IDE? Whats the relationship between them and also with wiring?

Processing sketches are written in Java. Arduino sketches are written in C++. Wiring was the predecessor to the Arduino (hardware) design. It had it's own language.

  1. I declare a bunch of initialized variables at the beginning of loop(). For instance boolean runningFast = false; or keylineState = NOT_TRANSMITTING. Are each of these variables re-initialized every time through?

Yes, they are reset on each pass through loop. Technically, they go out of scope at the end, and are recreated at the start.

Putting them at global scope, (say, just above loop()) seems a little drastic, just to prevent re-initialization.

Making them static accomplishes the same thing, but keeps the scope local.

  1. In the description of "Constants" in the language section on the web site there is a nice description of HIGH and LOW. But it doesn't include their values.

1 and 0, but it doesn't really matter. You should use HIGH and LOW.

For a predicate like X != HIGH there's no problem, but what about !HIGH or !LOW?

What about them? They work.

Are HIGH and LOW aliases for boolean values?

No. They are simply defined names with associated values.

PaulS:

For a predicate like X != HIGH there’s no problem, but what about !HIGH or !LOW?

What about them? They work.

He’s asking good questions though. Say LOW is 1, and HIGH is 2. Then !LOW is not the same as HIGH.

The only reason !LOW is == HIGH is because LOW is 0 and HIGH is 1.

@op:

See Arduino.h:

#define HIGH 0x1
#define LOW  0x0

You can alway use something along the lines of the following to ‘toggle’ states:

// Bitwise XOR <http://www.arduino.cc/playground/Code/BitMath>
inline uint8_t toggleState(uint8_t& vstate, uint8_t const state1 = LOW, uint8_t const state2 = HIGH)
{
    return (vstate ^= (state1 ^ state2));
}

...

toggleState(state);

...

The result of which can be used in conditionals.

Or more simply

x = 1-x; //results in 1,0,1,0 every pass thru.

As does x ^= 1; :grin:

  1. I declare a bunch of initialized variables at the beginning of loop(). For instance boolean runningFast = false; or keylineState = NOT_TRANSMITTING. Are each of these variables re-initialized every time through?

Yes, they are reset on each pass through loop. Technically, they go out of scope at the end, and are recreated at the start. --> Just looking to avoid reinitializing the heap each time thru.

Putting them at global scope, (say, just above loop()) seems a little drastic, just to prevent re-initialization.

Making them static accomplishes the same thing, but keeps the scope local. --> Yes. Tnx.

For a predicate like X != HIGH there's no problem, but what about !HIGH or !LOW?

What about them? They work. -->I just thought the values should be included in the doc page. Like many of the "Constant Field Values" found in the JavaDoc for the JAVA API

Tnx to everyone for their replies

--Lenny W.