Writing bits of byte number

hello,

I am trying to write an 8-bit number to a register of programmable sound generator.
Low four bits are used for frequency and higher four bits are used for volume.
Frequency and volume should be independly controlled by potentiometers connected to arduinos
analog inputs.

So, after reading value I will get number between 0-15 from each potentiometer.

Can you help me how can I write them to my 8-bit number please?

for ex:

volume = analogRead(A0) >> 6;
frequency = analogRead(A1) >> 6;

if frequency will be for ex. 10 and volume will be 8 then writing to register should look like this

myRegisterWrite(regNum, B10001010);

am I right?

how the code of writing should be please?

Thank you.

You got the volume right.

val = (analogRead(A0) >> 6)  + ((analogRead(A1) >> 2) & 0xFO);

thank you for fast answer! I will try it...

yes, seems it works! But I think there must be 0xF0 instead of 0xFO :slight_smile:

yoopee:
yes, seems it works! But I think there must be 0xF0 instead of 0xFO :slight_smile:

D'oh!