I'm working with RN52 (sparfun) and I can increase the volume with the actions command AV+ (or decrease with AV-). What I want to implement too is to set a volume in a certain level with potentiometer. The potentiometer works fine but when I set the volume, nothing happen. I use the HV action command (example HV,8\r).
How can I do this (ajust the volume with potentiometer) with RN52?
It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).
Try this
void volume()
{
//The action command is HV,<decimal>. All commands must end with \r
val = analogRead(pinVol);
val = map(val, 0, 1023, 0, 15);
mySerial.print("HV,");
mySerial.print(val);
mySerial.print('\r');
Serial.print("value ");
Serial.println(val);
}
Also, add a suitable delay to your loop() because at the moment it is trying to send instructions hundreds of times per second. Try delay(300); to start with.
You also only need to send data if the potentiometer is moved.
I see what you mean. The last linked document is newer.
Maybe you need the SS command. But I think it requires a value sent as hex text (very strange) so try this
void volume()
{
val = analogRead(pinVol);
val = map(val, 0, 1023, 0, 15);
char hexVal;
if (val < 10) {
hexVal = val + '0';
}
else {
hexVal = val + '7'; // the code for 7 is 55 + 10 gives 65 which is the code for A
}
mySerial.print("SS,0"); // first hex digit is always 0 in this case
mySerial.print(hexVal);
Serial.print("value ");
Serial.print(val);
Serial.print( " hexVal ");
Serial.print(hexVal);
}