About the "int" data type variable


i looking @ example code , noticed these lines:

code: [select]
// constants won't change. used here
// set pin numbers:
const int ledpin =  13;      // number of led pin

// variables change:
int ledstate = low;             // ledstate used set led
long previousmillis = 0;        // store last time led updated


my question is, if "int" type stores integers, why being used store "low?" why not make compiler error?

later in program use this:
code: [select]
  if(currentmillis - previousmillis > interval) {
     // save last time blinked led
     previousmillis = currentmillis;   

     // if led off turn on , vice-versa:
     if (ledstate == low)
       ledstate = high;
     else
       ledstate = low;

     // set led ledstate of variable:
     digitalwrite(ledpin, ledstate);


so question is, int variable lets store "low" or "high" in it, , not number?

second question wouldn't program better (more memory efficient) change ledstate , do, example:

code: [select]
boolean ledon=true;

thanks!

quote
my question is, if "int" type stores integers, why being used store "low?" why not make compiler error?

because low defined replaced zero.

you better storing in "byte" (uint8_t) variable.

what see:
code: [select]
digitalwrite (pin, low);

what compiler sees:
code: [select]
digitalwrite (pin, 0);


Arduino Forum > Using Arduino > Programming Questions > About the "int" data type variable


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support