Pages: 1 [2]   Go Down
Author Topic: Function Declaration Error  (Read 2023 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes sir,
the command is the
  • and [1], the port is [2] and [3] and the value is [4][5][6].
example :
byte myCommand[] = {0,8,2,8,4,7,5};
getCommand(myCommand) will get me:
command = 08
port = 28
value = 475

Thank you.
Logged


UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 304
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, you'll probably want to do something different then; or you'll have to use a word long instead of int for value (3 x bytes is too much for an int).

Try some base10 math

iCommand = ((int)command[0] * 10) + (int)command[1]
iValue = ((int)command[4] * 100) + ((int)command[5] * 10) + (int)command[6]
etc. etc.

Edit: I said word, I meant long.
« Last Edit: August 25, 2010, 06:06:20 am by Eight » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

May you explain me more about thous lines please?
Logged


UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 304
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, if your command inputs are only from 0-9 (it won't work with numbers above 9) then you can combine them by multiplying.

E.g.

TWO DIGITS
Command[0] = 9
Command[1] = 5

9 * 10 = 90
+
5
= 95

THREE DIGITS
command[4] = 2
command[5] = 1
command[6] = 0

2 * 100 = 200
+
1 * 10 = 10
+
0
= 210

The (int) parts cast the byte to an int, because our maths will exceed the capacity of a byte.

If a single input e.g. command[0] can be greater than 9 then you might need to go back to bit shifting and using the long datatype.

« Last Edit: August 25, 2010, 06:19:54 am by Eight » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you !  smiley-grin
Logged


Pages: 1 [2]   Go Up
Jump to: