How to read values greater than 255?


hi,
i started using i2c , want run continuous rotation motor speed implemented user through udp (this part have accomplished).
the master 1 sending "slave" speed should go. however, trying write integer value greater 255 second arduino (i.e 1030).

below snippet of master code:
code: [select]

int right = 0;
int motorspeed = 0;
.............
case 0x00: // motor turning right
 right = 1024 - motorspeed; // 1024 reference point of motor there no speed above 1024 go left below go right.
 wire.begintransmission(2);
 wire.write (right);
 wire.endtransmission();
 break;


below snippet of slave code:
code: [select]

while(wire.available())
 {
   int motorspeed = wire.read();

   if (motorspeed == 0)
   {
     myservo.write (1024); //motor stopped
   }
   else
   {
     myservo.write(motorspeed); //write speed received
   }
 }


thus, clarify problem, have been searching , found out integer big read.
but amateur programmer am, wondering if can me on how go inputting/ receiving values greater 255?

thanks in advance! :)

send 2 bytes. can split value int 2 bytes this
code: [select]

byte1 = value >> 8;
byte2 = value & 0xff;


Arduino Forum > Using Arduino > Programming Questions > How to read values greater than 255?


arduino

Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

How to format a Get Request

avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0x62