From a8bf3fd7e051fa1aa36350c3f83407a6b12d2b2b Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 11 Jun 2017 00:22:50 +0200 Subject: [PATCH] Move log10 for audio volume from nodered to arduino pro mini and fix scaling --- firmware_arduino_mini/firmware_arduino_mini.ino | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/firmware_arduino_mini/firmware_arduino_mini.ino b/firmware_arduino_mini/firmware_arduino_mini.ino index aefcfcf..c921fe7 100644 --- a/firmware_arduino_mini/firmware_arduino_mini.ino +++ b/firmware_arduino_mini/firmware_arduino_mini.ino @@ -1,3 +1,4 @@ +#include #define PIN_DATA_VOL_A 8 #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 // function take from here: http://forum.arduino.cc/index.php?topic=244152.0 void setVolume(uint8_t volume, uint8_t dataPin) { @@ -171,7 +177,7 @@ void loop() { } int vol=ser.substring(2).toInt(); - setVolume(vol,datapin); + setVolume(logify(vol),datapin); } else if(command == 'r') { // relais