If with 2 floats

So, I am using a potentiometer that's output is wired to an analog pin on the arduino. The arduino takes the value from an analogRead() and divides it by 401.11 to control my digipot on a scale from 0-255. The reason why I am doing this is so I can modify the output from the potentiometer.

          if(pedalPos >= motorPower){
            motorPower++;
            delay(10);
            break;
            Serial.println("TEST");

pedalPos is the potentiometers position, from 0-255, and motorPower is currently a variable set to 0. I have the digipots output hooked up to a oscilloscope. But as seen from this, the variable motorPower is not written to the potentiometer, but what I am looking for is "TEST" in the serial monitor, which does not show. I know that the pedalPos is greater than the motorPower(motor power and pedalPos are defined as such(float motorPower = 0.0 [new line] float pedalPos = 0.0). I know that the pedalPos changes its value with the piece of code before that "getPedalPos()" a function I made. Anyone know why this isn't working?

1Ghasthunter1: ...what I am looking for is "TEST" in the serial monitor, which does not show.

I wonder if that break is the culprit.

Why floats. Why divide.

Use int for pedalPos and motorPower.

And map whatever range of the pedalPos to whatever range of motorValue.

https://www.arduino.cc/en/Reference/Map

Post all of the code if you want meaningful help. Leo..

Why are you dividing by 401.11? You should just be diving by 4. The analog POT reads 0-1023, and it appears you have a Digi-POT which reads 0 - 255. So 1024 divided by 256 is 4.

Can you post the rest of the code?

Are you doing a "pedalPos = analogRead(POTpin);", where "POTpin" is declared as the analog pin where the wiper of the potentiometer is connected?

Then do "pedalPos = pedalPos/4;" Or you can combine them into one statement of "pedalPos = analogRead(POTpin)/4;"

Also, just to be sure: You have 5v and GND on the other 2 leads of the POT, correct?

I don't think you need float here either, as the Digi-POT only has 256 steps. So you cannot set a value with a decimal for the Digi-POT. I would use "int motorPower = 0;" and "int pedalPos = 0;" instead of float in your variable definitions.

I am doing something very similar with analog POTs and digital POTs, and I just have the code dividing by 4, and it's working.

pedalPos = analogRead(POTpin) >> 2; // will this divide by 4 faster?

But OP might want to change a pedalPos of 12-789 to 30-255.
Then map should be used.
Leo…

Wawa: pedalPos = analogRead(POTpin) >> 2; // will this divide by 4 faster?

From an eight-bit-RISC-processor perspective that would be four clock cycles of work. So, let's see what the compiler produces...

  pedalPos = analogRead(POTpin) >> 2; // will this divide by 4 faster?
 528:   95 95        asr r25
 52a:   87 95        ror r24
 52c:   95 95        asr r25
 52e:   87 95        ror r24

Four one cycle instructions. Can't beat that.