SGTL5000 volume(level);

Status
Not open for further replies.

damo1976

Well-known member
I need to print the value of the volume(level) function as it is changed by a pot which is the headphone volume,
out to a serial but I need to map it to 1 - 10 with .5 step increments..
Currently its a float that goes from 0 - 1

Any idea how to code this?
 
This is all the code that deals with it.

#include <Encoder.h>

#define ENCODER_OPTIMIZE_INTERRUPTS

//Pins for rotary encoder (must be interrupt enabled
int enc_pin1 = 16; // 3 on connector CN11
int enc_pin2 = 17; // 4 on connector CN11

// Encoder Variables
int Enc; // ROTARY ENCODER
long old_enc_pos = 0; // past encoder position
long new_enc_pos; // new (current) encoder position
int enc_diff=0; // difference between old and new (after scaling - dividing by 4)
Encoder Enc1(enc_pin1, enc_pin2);


void setup() {

}

void loop() {

new_enc_pos = Enc1.read() / 4;
if (new_enc_pos != old_enc_pos) {
enc_diff = (new_enc_pos - old_enc_pos);
old_enc_pos = new_enc_pos;
}



if (enc_diff) {

headphoneLevel = headphoneLevel+enc_diff;
if (headphoneLevel<0) headphoneLevel=0;
if (headphoneLevel>20) headphoneLevel=20;
AudioShield.volume((float)headphoneLevel / 20);
Serial.println(map(headphoneLevel, 0, 20 , 0 , 10), 1);
enc_diff=0; old_enc_pos = new_enc_pos;
}

}
 
Status
Not open for further replies.
Back
Top