Been away from Arduino coding for a while and some brain cells seem to have died in the interim...
Basic, basic question: I want to send a value from a Processing sketch in the range of 0-1023. I want to use the value to control PWM. So with the range mentioned I need to send 4 bytes - but I don't recall how to reassemble them on the Arduino side. I get the gist of bitshifting but am having trouble putting it together.
Avoiding the points made by AWOL, you can re-assemble 2-byte integers using lowbyte() and highbyte() and the Logical OR operator.
Bitshift the highbyte by 8 positions then OR it with the lowbyte.
Hi - thanks for the replies. I guess I could have been a bit clearer in my initial post. I am using shiftBrite LEDs and they take a range of 0>1023 for PWM. I need to make a little color picker tool in Processing so I can determine how particular rgb colors are represented by the shiftBrites and then try to use an adjustment factor so the LED color is closer to the rgb color. (I posted separately @ this).
@ the number of bytes to send - it is my understanding that for the Arduino to receive a value of 1023, it has to read 4 bytes - one for each of the numerals - and then reassemble them using the method Mitch_C mentioned. Am I completely off the planet here?
the number of bytes to send - it is my understanding that for the Arduino to receive a value of 1023, it has to read 4 bytes - one for each of the numerals
If you're sending the value as an ASCII string yes, you need at least four bytes for that size number. "At least" because you'll probably want to send some delimiter to distinguish one number from the next.
However, 0..0123 can be represented in only 10 bits. You'll still need some form of delimeter, which can be tricky working in only binary.
It depends on if you need the higher update rate a shorter representation can give.