INT into BYTES for VMUSIC volume

Hi,

I've managed to set the volume manually for this VMUSIC module:

http://www.vinculum.com/prd_vmusic1.html

But now I want to use a POT to control it. But I've got stuck because I'm not sure how to convert the POT reading from a INT into a BYTE. Does anyone have any ideas? Do I have to create an array with all the possible BYTEs or is there an easier way to convert between INTs and BYTES?

Here's my code:

Serial1.print("VSV ");
Serial1.print(0x0A,BYTE); // set the voloume. Needs to be a value between 0x00 and 0xFE (0x00 being high)
Serial1.print(0x0D,BYTE);

Any help much appreciated

Cheers

Boppyer

volumeVal = map (potVal, 0, 1023, 0, 255);
or volumeVal = potVal / 4;

Your code sample shows "VSV " "carriage-return/line-feed", equivalent to
"Serial1.println ("VSV ");

hello

Your code sample shows "VSV " "carriage-return/line-feed", equivalent to
"Serial1.println ("VSV ");

does mean it's wrong? Sorry am a bit confused as the code I entered works but I don't know how to convert the POT reading which would be an Interger into a BYTE, maybe I'm missing something simple.

I just need to be able to change this: 0x0A,BYTE
from my Pot reading :slight_smile:

Many thanks

Boppyer

If I'm reading the manual at http://www.vinculum.com/documents/fwspecs/UM_VinculumFirmware_V205.pdf page 54 correctly, "VSV" = 0x88

so you need to send "0x88 0x20 0x0D"

[edit]OTOH, reading page 58, zero is maximum volume.
Check with the mfrs.

OK I actually RTFM.

"VSV"

Putting "line-feed" as an example volume was a really, really bad idea >:(

Hi,

do you mean my example "0x0A"

I used that because I thought it translated to 10 in decimal?

Sorry for the confusion but I'm still stuck as to how to insert a byte that's based from a INT from the pot. It doesn't seem to work if I just send it 10 but does if I send it as a BYTE equivalent.

cheers

boppyer:-)

do you mean my example "0x0A"

Too damn right! :slight_smile:

As I said earlier:

volumeVal = map (potVal, 0, 1023, 0, 255);
or volumeVal = potVal / 4;

Explanation: "analogRead" returns a value 0..1023, but you need a value 0..255.
HOWEVER: the manual seems to suggest that the louder you expect the thingy to be, the lower you should specify the value.

So, depends how you've got your pot wired whether you use:
byte volumeVal = map (potVal, 0, 1023, 0, 255);
or
byte volumeVal = map (potVal, 0, 1023, 255, 0);

Your call, my bedtime.

thanks :slight_smile: sorry for the LR :-p I'll give it a got and let you know.

This is what I ended up using:

// ------------------------------------------------------------
// readVolumePot - reads the potentiometer for volume
// ------------------------------------------------------------
void readVolumePot(){

  potVal = analogRead(0);    // read the value from the sensor
  
  // maps the pot value to between 0 and 90. 
  // The manual says the volume settings are between 0 and 254. 
  // Where 0 sets the volume to it's highest.
  // But I found that the best range is between 0 - 90
  byte potReading = map (potVal, 0, 1023, 90, 0); 

  if (potReading != lastPotReading){
    setVolume(potReading);
    lastPotReading = potReading;
    Serial.println("Setting volume");
  }
}

// ------------------------------------------------------------
// setVolume - sets VMUSIC's volume based on readVolumePot
// ------------------------------------------------------------
void setVolume(byte volumeVal){
// This is the command that needs to be sent to VMUSIC 
  Serial1.print("VSV ");
  Serial1.print(volumeVal,BYTE); 
  Serial1.print(0x0D,BYTE);
  Serial.println("Volume has been set");

}

It's using a Arduino Mega so you need to change the Serial settings if you want to use it on anything else

I used that because I thought it translated to 10 in decimal?

So, it doesn't go to eleven then? :sunglasses:

Sorry for the misunderstanding - after very many years in this game, I see 0x0d and 0x0a in close proximity, and I just see CR/LF (or in this case, LF/CR!)