Simple, Stupid Question....

Hi,

I had a silly question.

I'm looking at this code:

// Example 02: Turn on LED while the button is pressed
//
// Copy and paste this example into an empty Arduino sketch

#define LED 13   // the pin for the LED
#define BUTTON 7 // the input pin where the
                 // pushbutton is connected
int val = 0;     // val will be used to store the state
                 // of the input pin 

void setup() {
  pinMode(LED, OUTPUT);   // tell Arduino LED is an output
  pinMode(BUTTON, INPUT); // and BUTTON is an input
}

void loop(){
  val = digitalRead(BUTTON); // read input value and store it

  // check whether the input is HIGH (button pressed)
  if (val == HIGH) { 
    digitalWrite(LED, HIGH); // turn LED ON
  } else {
    digitalWrite(LED, LOW);
  }
}

And I'm unclear on something....val = digitalRead(BUTTON);

My understanding is that reading the button will give you HIGH or LOW. But these aren't integers, they are strings.

So how can HIGH be assigned to a integer? Unless HIGH really = 1, and LOW = 0, and the Arduino compiler knows this and converts them behind the scences automatically?

I know it's a dumb question, but I just want to make sure I'm not crazy =)

Thanks!

reading the button will give you HIGH or LOW. But these aren't integers, they are strings.

They are hash defined quantities. The compiler automatically converts these into numbers for you.
The definition is buried in the system files. maybe some one can point you to it.

The compiler doesn't know about HIGH and LOW until you tell it (they're not 'C' keywords), implicitly by including "wiring.h".

They're not strings either; for that, they'd be enclosed in quotes (")

You're sanity is assured. :smiley:

Great, That's what I thought. Thanks guys!