Thursday, 22 January 2015

Data-types used on Arduino


Except in situations where maximum performance or memory efficiency is required,Variables declared using int will be suitable for numeric values if the values do not exceed the range and if you dont need to work with fractional values.Most of the official Arduino example code declares numeric variables as int.But sometimes you do not need to choose a type that specifically suite your application.

UNSIGNED AND SIGNED

Sometimes you need negative numbers and sometimes you don't, so numeric types come in two varities:signed and unsigned.unsigned values are always positive.
variables without keyword unsigned in front are signed so that they can represent negative and positive values.one reason to use unsigned values is when the range of signed values will not fit in the range of the variable .

BOOLEAN

They have two values namely : True or false. They are commonly used in situations in order to check the state of the switch to know whether it is ON or OFF.

Example for boolean

int Switch=10;
void setup()
{
  pinMode(Switch,INPUT);
  Serial.begin(9600);
}
void loop()
{
     boolean switchstat;
     int switch1=digitalRead(Switch);
     if(switch1==HIGH)
    {
         switchstat=true;
     }
     else
    {
        switchstat=false;
    }
   if(switchstat==true)
   {
              Serial.println("LIGHTS ON");
   }
   else
   {
              Serial.println("LIGHTS OFF");
    }
}


Next post on using FLOATING-POINT NUMBERS

No comments:

Post a Comment