Pages: 1 2 [3]   Go Down
Author Topic: PWM - Fade a pin  (Read 1985 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't have an arduino at hand, so I tested this on linux:

Code:
#define ARY_LEN(a) (sizeof(a)/sizeof(a[0]))

#define CMD_MAX_LEN 50

char cmdArray1[][CMD_MAX_LEN] = {
    "COM1",
    "COM2",
};

char cmdArray2[][CMD_MAX_LEN] = {
    "COM1",
    "COM2"
};

void main(int argc, char** argv) {
    printf("ary len 1 = %d\n", ARY_LEN(cmdArray1));
    printf("ary len 2 = %d\n", ARY_LEN(cmdArray2));

    printf("sizeof(ary1) = %d\n", sizeof(cmdArray1));
    printf("sizeof(ary2) = %d\n", sizeof(cmdArray2));
}

Result:
Code:
ary len 1 = 2
ary len 2 = 2
sizeof(ary1) = 100
sizeof(ary2) = 100
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 47
I'm glad I bought an Arduino Leonardo
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Using ARY_LEN(commands) is IMHO more convenient than having to update a constant every time you add or remove a string from the array.

I agree!
Logged

Pages: 1 2 [3]   Go Up
Jump to: