Move log10 for audio volume from nodered to arduino pro mini and fix scaling
This commit is contained in:
parent
4f6f68bc09
commit
a8bf3fd7e0
|
@ -1,3 +1,4 @@
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#define PIN_DATA_VOL_A 8
|
#define PIN_DATA_VOL_A 8
|
||||||
#define PIN_DATA_VOL_B 7
|
#define PIN_DATA_VOL_B 7
|
||||||
|
@ -106,6 +107,11 @@ void switchInputs(uint8_t channel, bool state) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t logify(uint8_t volumelinear){
|
||||||
|
double volumelog=log10( ((double)volumelinear)/10.0 +1)*97;
|
||||||
|
return (int)volumelog;
|
||||||
|
}
|
||||||
|
|
||||||
// control a M62429 Chip for Volume Control
|
// control a M62429 Chip for Volume Control
|
||||||
// function take from here: http://forum.arduino.cc/index.php?topic=244152.0
|
// function take from here: http://forum.arduino.cc/index.php?topic=244152.0
|
||||||
void setVolume(uint8_t volume, uint8_t dataPin) {
|
void setVolume(uint8_t volume, uint8_t dataPin) {
|
||||||
|
@ -171,7 +177,7 @@ void loop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int vol=ser.substring(2).toInt();
|
int vol=ser.substring(2).toInt();
|
||||||
setVolume(vol,datapin);
|
setVolume(logify(vol),datapin);
|
||||||
|
|
||||||
} else if(command == 'r') { // relais
|
} else if(command == 'r') { // relais
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue