Read value of 2pots and print the samee on 2 MCP4725 DAC

Hello
im about to start my first project.
i need to read voltage from two potentiometers at the same time and then loop out the same voltage trough 2 MCP4725 DACs (voltage are not the same on each pot)
i also need to temporary lower and higher the outputvalue and ignore pot readings when certain switches are active.
i managed to do a simple circuit with som buttons,resistors caps and some coding to read 2 pots and the output PWM signals. but the device that im trying to control does not acceting the PWM very well

const int adc1 = 0 ;   //naming pin 0 of analog input side as ‘adc’
const int adc2 = 1 ;   //naming pin 0 of analog input side as ‘adc’
const int pwm1 = 2 ;    //naming pin 5 as ‘pwm’ variable 
const int pwm2 = 4 ;    //naming pin 3 as ‘pwm’ variable 
int potPin1 = A0;
int potPin2 = A1;
int pushButton1 = 50;   //naming pin 8 as "pushbutton
int pushButton2 = 52;   //naming pin 8 as "pushbutton
int resetPin = 14;


void setup() {

  Serial.begin(9600);
  
   pinMode(potPin1, INPUT);
   pinMode(potPin2, INPUT);

  
   pinMode(pwm1,OUTPUT) ;  //setting pin 2 as output'
   pinMode(pwm2,OUTPUT) ;  //setting pin 2 as output
   pinMode(52,INPUT_PULLUP);
   pinMode(50,INPUT_PULLUP);

 
   
  

  }


void loop() {


  //read the pushbutton value into a variable
  int sensorVal5 = digitalRead(52);
  int sensorVal4 = digitalRead(50);
  //print out the value of the pushbutton
  Serial.println(sensorVal5);
  Serial.println(sensorVal4);

  // Keep in mind the pull-up means the pushbutton's logic is inverted. It goes
  // HIGH when it's open, and LOW when it's pressed. Turn on pin 13 when the
  // button's pressed, and off when it's not:
  if (sensorVal5 == HIGH) {
    digitalWrite(13, LOW);
  } else {
    digitalWrite(13, HIGH);
  }

  
   if (sensorVal4 == HIGH) {
    digitalWrite(13, LOW);
  } else {
    digitalWrite(13, HIGH);
  }


  int adc1  = analogRead(0) ;    //reading analog voltage (0) 
  int adc2  = analogRead(1) ;   //reading analog voltage (1) 
  int ao = analogRead(1) ;
  Serial.println(adc2);
  Serial.println(adc1);

   if (sensorVal5 == LOW && sensorVal4 == HIGH) {
    
    adc1 = map(adc1, 0, 3000, 0, 255) ; 
    analogWrite(pwm1,adc1) ; 

    
       adc2 = map(adc2, 0, 2500, 0, 255) ; 
       analogWrite(pwm2,adc2) ;
    
  } else {
    
    adc1 = map(adc1, 0, 1023, 0, 255) ; 
    analogWrite(pwm1,adc1) ;
    
    
      adc2 = map(adc2, 0, 1023, 0, 255) ; 
      analogWrite(pwm2,adc2) ;
  }

     if (sensorVal5 == HIGH && sensorVal4 == LOW && ao <=250) {
    
    adc1 = map(adc1, -2000, 1023, 0, 255) ; 
    analogWrite(pwm1,adc1) ; 

    
       adc2 = map(adc2, -2000, 1023, 0, 255) ; 
       analogWrite(pwm2,adc2) ; }

basicly pot value1 and 2 are looped trough the arduino and outputs the scaled value 0-1023 in PWM 0-255
but when one of the pushbuttons are pressed, the input scaling differs and the output lowers depending on switch or rises the scaing if the other switch and ao value is lower then 250.

now to my problem.

i manage to read the pots and output som kind of linear value on the DACS but i dont know how to get the map function included in the buffer values

#include <Wire.h> // specify use of Wire.h library
#define MCP47251 0x62 // MCP4725 base address
#define MCP47252 0x63 // MCP4725 base address

int val1 = 0 ; 
int val2 = 1 ; 
byte buffer[3];

void setup()   {

  Wire.begin(); // begin I2C

}  // end setup

void loop() {



    buffer[0] = 0b01000000; // control byte
  val1 = analogRead(0) * 4; // read pot
  buffer[1] = val1 >> 4; // MSB 11-4 shift right 4 places
  buffer[2] = val1 << 4; // LSB 3-0 shift left 4 places

  Wire.beginTransmission(MCP47251); // address device
  Wire.write(buffer[0]);  // pointer
  Wire.write(buffer[1]);  // 8 MSB
  Wire.write(buffer[2]);  // 4 LSB
  Wire.endTransmission();

  
    buffer[0] = 0b01000000; // control byte
  val2 = analogRead(1) * 4; // read pot
  buffer[1] = val2 >> 4; // MSB 11-4 shift right 4 places
  buffer[2] = val2 << 4; // LSB 3-0 shift left 4 places

  Wire.beginTransmission(MCP47252); // address device
  Wire.write(buffer[0]);  // pointer
  Wire.write(buffer[1]);  // 8 MSB
  Wire.write(buffer[2]);  // 4 LSB
  Wire.endTransmission();

does anybodu understand what i need help with? im stuck

Is that device You want to control by PWM a secret? If not give us its data or a link to its data sheet.
Make a drawing of the wiring including power supplies.

Something like this :o :confused:

Sorry but Your picture has faar to less of resolution and blurrs of when magnified. Take pen and paper and make a larger drawing.
I don't see how, where and what power is supplied.

Have you clicked twice? I can see perfectly

Okey, that's a bit better. I se no powering of the project. The positive to the pots I don't get. The DACs....
The 2 buttons are not used at all in the code I can see. I see no declarations in Setup.

Always post the entire code if You want us to help. Too often faults are found in places OP never guesses.

Power to arduino is the VIN and power to pots comes from the ECU

Both ecu and arduino shares the same powersupply

About the buttons. They are included in the first code that put out a pwm signal

Also both pots. Ecu and arduino shares the same GND

Be more precise. "Power to arduino is the VIN" What is connected there? Volt, Amps...? Several possibilities to trouble there.
What is powering the ECU? The same "mysterious" voltage...?

Buttons reading.... Where is the debouncing logic?

Im so sorry. I will make a better drawing tomorrow

Soo often soo small things makes all the difference. Wiring diagram, links to all stuff around the controller, complete code..... Standard requirements from most helpers.
It's all told in the leading topics like "How to use thsi Forum", "How to get the best of Forum".
There is some text to read but following the advice the road to the solution gets much shorter.

i need to read voltage from two potentiometers at the same time

Seeing that there is only one A/D on the Arduino you can’t read two values at the same time. One after the other is the best you can get. Normally it will take you 100uS to read a sample.
Writing out to an I2C device also takes 100uS per byte, each transfer will take at least two bytes and often more.