Process a binary word into 2 PWM outputs

Hi,

I have had a project land on my desk involving an arduino. I have never looked at one before and have no experience programming one. (Thanks to staff shortages...)

Basic premise. I need to take an 8 bit binary word input from a raspberry pi and using the 1st 4 bits output a pwm signal on one pin and using the 2nd 4 bits output another pwm signal on another pin.

I found the servo library and was able to get the two signals to output based on voltage inputs from potentiometers but i now need to use the binary word.

Thanks for your Help.

Is that like :

1101 0011, such as '13' and '3' ?

So take the whole 8 bits, and do a logical bit-wise "AND" with 0000 1111 to get:

0000 0011, which will represent the value associated with the lower four bits.

Then take the original 8 bits again, and bit-wise "AND" with 1111 0000 to get:

1101 0000, which can then be shifted right by 4 bits......to give :

0000 1101, which will represent the value associated with the upper four bits.

Alternatively, take the original 8 bit word, then just shift right by four bits to get...

0000 1101, which also gives the value associated with the upper four bits.

Did you want the values 0 to 15 to represent something other than a servo angle from 0 to 15 degrees?

Note: When you right shift your byte, make sure it is unsigned. If not the sign-extension may be confusing.

For signedness: shift the byte first, then mask out the excess bits.

Please note that servo signals and PWM are somewhat different - which one do you really need?