Pages: [1]   Go Down
Author Topic: i2c and integer  (Read 469 times)
0 Members and 1 Guest are viewing this topic.
cuneo
Offline Offline
God Member
*****
Karma: 3
Posts: 785
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hello,
at first excuse me for my english,

i have a question i use wire library to trasmit between 2 arduinos and i don't know if i can trasmit an integer value. if i can, how i can do it?

thank you
Logged

Sheffield --- UK --
Offline Offline
Sr. Member
****
Karma: 0
Posts: 377
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I would imagine you can send anything, but only a byte at a time.
So you would get the number and use mod & div to split the number up.
Logged


London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here is an example:

  Wire.send((byte)(integerValue >>smiley-cool);     // sends the most significant byte    
  Wire.send((byte)(integerValue & 0xff));    // sends the least significant byte

the receiving side has to reconstruct the integer
  val = Wire.receiver() << 8; // get the msb
  val += Wire.receive(); // get the lsb
« Last Edit: February 04, 2009, 11:44:16 am by mem » Logged

cuneo
Offline Offline
God Member
*****
Karma: 3
Posts: 785
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

thank you very much
Logged

Pages: [1]   Go Up
Jump to: