Tutorial 2 - Let’s start playing…!!!
As it is stated in previous post that we
aren’t going to start will all those repeating basic programs but still here
are some most important commands that will be used throughout our tutorial series.
Serial.println(value);
Prints the value to the Serial Monitor on your computer
pinMode(pin, mode);
Configures a digital pin to read (input) or write (output) a
digital value
digitalRead(pin);
Reads a digital value (HIGH or LOW) on a pin set for input
digitalWrite(pin, value);
Writes the digital value (HIGH
or LOW) to a pin set for output
Now all of you know how to
turn on a led using arduino. But if I want to use decimal number for our
program then. We will use float number, here suppose we want to add some
decimal numbers and want to print them.
float value = 1.1;
void setup()
{
Serial.begin(9600);
//open
the serial port to send data back to the computer at 9600 bits per //second
}
void loop()
{
value = value + 0.1; // increase value by 0.1 each time through the
loop
Serial.println("The value is
");
Serial.println(value);
delay (1000);
}
We
will use the above code for our purpose. Floating point approximates numbers
because it only uses 32 bits to hold all values within a huge range. Eight bits
are used for the decimal multiplier (the exponent), and that leaves 24 bits for
the sign and value—only enough for seven significant decimal digits. But
remember that although float and double are exactly the same on Arduino, doubles
do have a higher precision on many other platforms. If you are importing code
that uses float and double from another platform, check that there is
sufficient precision for your application.
That’s
it for this week. Next time we will look for some arrays, strings and lots
more.
Comments
Post a Comment