PWM Help for NEW user

I am trying to update a PWM to slowly increase the speed of a DC motor. The PWM is switching a transistor. I am trying to start slowly and increase the PWM by which increasing the speed of the motor each time through the loop. See the code below:

int motor = 10;
int a = 20;

void setup()
{
pinMode(motor, OUTPUT);
}

void loop()
{
analogWrite(motor,a);
a+1;
}

The PWM is staying at the initial value of 20 and never increasing. Does anyone know why this is not updating each time through the loop.

Thanks in advance for any help that can be given.

The Arduino processor is simply too fast. You will need to slow it down a bit. You'll also need to clamp a. Give this a try...

int motor = 10;
int a = 20;

void setup()
{
pinMode(motor, OUTPUT);
}

void loop()
{
analogWrite(motor,a);

if ( a < 255 )
{
a = a + 1;
}

delay( 10 );
}

Thanks so much. This seems to work exactly how I needed it to for what I am trying to accomplish. I think that delays will have to become my friend. I am sure I will be on the forums quite a bit in the coming weeks.

Thanks

Jon

I think that delays will have to become my friend

Sad to say, it won't be a lasting friendship :wink: