Issue with PWM statement

Hello all. Some days I just hate Arduinos >:(

Running a fan on PWM.

const int Lift_fan = 3;
int Lift_fan_speed=500; //Lift fan start speed

If I write:
analogWrite(Lift_fan,500);
Then all is well. The fan starts, I can adjust that second value and control the speed.

But.... if I write:
analogWrite(Lift_fan,Lift_fan_speed);
It doesn't work. The motor doesn't run.

Lift_fan_speed shows as a value of 500 in debug.

Eh? What is the difference between the analogWrite using a fixed value and a variable?

There is no difference.

The problem must be elsewhere. Show us the rest of the code.

The problem is that analogWrite is only 0-255. Not 0-1023 as I assumed (as analogRead is).

However, I have noted that I don't seem to be able to increment the value Lift_fan_speed by saying:

if (something happens) {Lift_fan_speed++;}

It refuses to allow that.

I will have to lift the code when I get back

Arduino_Steve:
Hello all. Some days I just hate Arduinos >:(

It’s a poor craftsman who blames his tools.

Arduino_Steve:
The problem is that analogWrite is only 0-255. Not 0-1023 as I assumed (as analogRead is).

Yeah that's true, I didn't spot that. It shouldn't make a difference though, whether 500 is a literal or the value of a variable the results should be the same.

if (something happens) {Lift_fan_speed++;}

It refuses to allow that.

That should be fine too. How does it refuse to allow it? Does it refuse to compile? Does it crash? Some other expected result?

gfvalvo:
It’s a poor craftsman who blames his tools.

No… its a flu riddled, fed up, tired man who blames his tools…

I just don’t get it, so walking a way for a bit.

It’s an odd one. As soon as I I change the value of Lift_fan_speed, the code hangs and will not run… at all.

If I say:

if (Sensor>100) {}

analogWrite(Lift_fans,Lift_fan_speed);

Then the motor turns at the speed (Lift_fan_speed) that was declared at the start of the program.

but, if I say:

if (Sensor>100) {Lift_fan_speed=200;}

analogWrite(Lift_fans,Lift_fan_speed);

Then code code will compile, but not run.

There are no other instances of Lift_fans or Lift_fan_speed in the code at all.

Bizarre (but probably some quirk of Arduinos I don’t understand).

We still have not seen a complete program that illustrates the problem.

UKHeliBob:
We still have not seen a complete program that illustrates the problem.

Relax… mere half an hour since op said he would post when he gets back, presumably to where the sketch is.