COMMAND OR FUNCTION

A couple of questions

I want to know if

  1. digitalWrite() is it a command or a function
  2. delay()_ a command or function.

They are functions.

BIGMAC1:
A couple of questions

I want to know if

  1. digitalWrite() is it a command or a function
  2. delay()_ a command or function.

Those are all functions. A function is a piece of code that (optionally) takes and/or returns data. For example, these are all functions:

int get_color (int x, int y)
{
    setCursor (x, y);
    return colorOf (pixel);
}

This code is a function, it's name is "get_color", it takes 2 parameters (an X and Y coordinate of a pixel) and returns one value (the color of the pixel). It's used like this:

** **int my_color = getColor (64, 128);** **

void delay_milliseconds (long int msec)
{
    while (msec--) {
        waste_one_millisecond();
    }
}

This function takes one number (how many milliseconds) and then delays by that many. The "void" means it returns nothing.

It's used like this:

delay_milliseconds (5000); // delay 5 seconds

void clear_ram (void)
{
    for (x = 0; x < 1024; x++) {
        memory_at_address [x] = 0;
    }
}

This function erases a block of memory from address 0 to address 1023. It takes no parameters and returns none - it just does it's job. You use it like this:

clear_ram();

Hope this makes sense and answers your question. Feel free to ask more if necessary.

(edit to add): These are just examples. They are not functions that are available in Arduino. I just made them up as examples.

Delta_G:
They are functions.

You were typing while I was typing and you won the race! :slight_smile:

THERE ARE NO COMMANDS IN C/C++

Mark

Is blue a colour, or is it a shade?

THERE ARE NO COMMANDS IN C/C++

This is true, and sort-of important. In some computer languages, there are a bunch of built-in "commands" that accomplish various things. BASIC or Pascal's "PRINT" command, for example. If you look carefully, you'll notice that the commands don't even follow the rules that exist for functions or subroutines (BASIC (the original basics) doesn't have named functions/subroutines. Pascal functions don't allow variable numbers of arguments, or arguments of different types.)

In C and C++, you have some reserved "keywords" ("if", "else", etc), but all the things that look sort-of like functions ARE exactly functions, just like you can write yourself.

PaulMurrayCbr:
Is blue a colour, or is it a shade?

To me, shade means "saturation" as in "a lighter shade of blue" would be less intense than "regular" blue.

westfw:
This is true, and sort-of important. In some computer languages, there are a bunch of built-in "commands" that accomplish various things. BASIC or Pascal's "PRINT" command, for example. If you look carefully, you'll notice that the commands don't even follow the rules that exist for functions or subroutines (BASIC (the original basics) doesn't have named functions/subroutines. Pascal functions don't allow variable numbers of arguments, or arguments of different types.)

In C and C++, you have some reserved "keywords" ("if", "else", etc), but all the things that look sort-of like functions ARE exactly functions, just like you can write yourself.

All Functions have hidden commands to work around hardware if there no command no functions existing

PA3040:
All Functions have hidden commands to work around hardware if there no command no functions extincting

Huh? I have no clue what you are trying to say.

bperrybap:
Huh? I have no clue what you are trying to say.

I think he means that in low level languages, such as C, the functions are closely matched to the hardware. This means that a compiles statement will be small, usually only an instruction or two per function. If a standard function does not fit in a short sequence of machine instructions for a particular processor, then external 'commands' may be used to perform the translation. These commands are often comprised of easily ported sequences of more basic functions.