Maurício Vilarinho - 5 months ago 12

C Question

I have rpm, max_rpm and a variable x.

**When rpm aproaches max_rpm -> x tends to 0**

**When rpm aproaches 0 -> x tends to 255**

`x = (rpm/rpm_max)*255;`

arduino.analogWrite(g,(int)x);

I have the exact opposite. What can I do? I'm really dumb to figure it out.

Answer

If I understood your question correctly then maybe this?

```
x = (1 - rpm/rpm_max)*255
```

UPDATE: as mentioned by CandiedOrange - rpm and rpm_max need to be float or double for it to work. Otherwise the value of x would simply switch back and forth between 0 and 255.