You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • I2C is sending by specification always 8 bits - the 8 lower bits of the bytes (or values in an array) you provide. Easiest is a plain integer number that you mask with & 15. Bits 5 through 7 (counting from 0 and LSB) get nulled. If you need to pack four booleans into 4 bit, you can do that by addition of the mapping values of 1, 2, 4, and 8. Unpacking can be done in a similar way... and the fun part is that JavaScript looks at any number that is not 0 as true in a logical statement, so receiving r = 6 can be masked out in to var bool0 = r & 1, bool1 = r & 2, bool2 = r & 4, bool3 = r & 8;, and the code logic (in JavaScript) is if (bool2) { // is true for r = 6... or you simply say if (r & 2) { .... That's one of the beauties of JS (and of course also a trap if you are not familiar with...). Bit masking/testing is not much different in Arduino world.

    To actually answer your question literally: just send 0 ( ....writeTo(..., 0, ...) ).

About

Avatar for allObjects @allObjects started