Me playing with the Software PWM library.

I am wanting to use it for some stuff.

The original code looks like this:

#include <SoftPWM.h>

void setup()
{
  SoftPWMBegin();
  
  SoftPWMSet(13, 0);

  SoftPWMSetFadeTime(13, 1000, 1000);
}

void loop()
{
  SoftPWMSet(13, 255);
  delay(1000);
  SoftPWMSet(13, 0);
  delay(1000);
}

The LED glows/oscillates as stated.

I want to use another pin.

This is my bit of code:

#include <SoftPWM.h>

#define led_pin 5


void setup()
{
  SoftPWMBegin();
  pinMode(led_pin,OUTPUT);
  
  SoftPWMSet(led_pin, 0);

  SoftPWMSetFadeTime(led_pin, 1000, 1000);
}

void loop()
{
  SoftPWMSet(led_pin, 255);
  delay(1000);
  SoftPWMSet(led_pin, 0);
  delay(1000);
}

I stick an LED in pin 5 of the arduino and a resistor to GND.

Nothing happens.

I stick an LED in pin 5 of the arduino and a resistor to GND.

Where does the other end of the LED go? The other end of the resistor?

Why did you add a pinMode() statement to the code? If the original code worked without it, why would you add it?

Paul,

I (personally) am in overload mode.

I am really not thinking clearly at the moment and am not the healthiest little camper.

So I guess those and a few other things are not helping.

The pin (which ever) goes to the LED (anode) then to the resistor then to GND/0V.

This is what I have so far now:

#include <SoftPWM.h>

#define led_pin 5

/*

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


void loop()
{
    int counter;
    counter = counter + 1;
    counter = counter %2;
    if (counter == 1)
    {
      digitalWrite(led_pin,HIGH);
    }
    delay(2000);
    if (counter == 0)
    {
      digitalWrite(led_pin,LOW);
    }
    delay(2000);
}
*/

void setup()
{
  SoftPWMBegin();
//  pinMode(led_pin,OUTPUT);
  
  SoftPWMSet(led_pin, 0);

  SoftPWMSetFadeTime(led_pin, 2000, 2000);
}

void loop()
{
  SoftPWMSet(led_pin, 255);
  delay(1000);
  SoftPWMSet(led_pin, 0);
  delay(1000);
}

Why the extra bit?

Well, because I stuffed up with the pinMode, and it didn’t work, I tried direct writing to the pin.

Dunno why even that doesn’t work.

Now, back to the main sketch - not remarked - the LED still does nothing.

Ofcourse the question is "which is the pin?

As 5, I am guessing it is the “bottom right most” pin of the board with the USB port on the left.

But nothing happens.

Putting it in the socket/hole/pin one to the left also nothing.

I’m stumped.

As 5, I am guessing it is the "bottom right most" pin of the board with the USB port on the left.

Guess again. The pin number refers to a digital pin, which would be on the top of the board, when the USB port is on the left. The one numbered 5.

Ah, the PWM 5 pin? So 0 is THE top right one - right?

Thanks a squillion.

Looks good now.

:)

I’m playing with this a bit more.

I can’t find good instructions for it.

Here is an example:

#include <SoftPWM.h>

#define led_pin 0

void setup()
{
  SoftPWMBegin();
  
  SoftPWMSet(led_pin, 0);

  SoftPWMSetFadeTime(led_pin, 5000, 5000);
}

void loop()
{
  SoftPWMSet(led_pin, 255);
  delay(1000);
  SoftPWMSet(led_pin, 0);
  delay(1000);
}

Now, if I make the delays more than 1000 to like 8000, it doesn’t seem to work.
It just “stalls” when the LED gets to the brightest stage.

If I change the two 5000’s in the first “config” part, to like… 8000 for SLOW rates, it doesn’t work.

I can’t really find a complete “README” file. Only the keywords file - which is ok, but doesn’t seem to tell me what the vaules are/mean etc.

Anyone please?

I can't really find a complete "README" file. Only the keywords file - which is ok, but doesn't seem to tell me what the vaules are/mean etc.

You have the source files. It is perfectly OK to look at them.

Yes Paul, I can look at the code.

But looking at it, is like reading a foreign language.

As much as I try to deconstruct the code I don’t understand it yet.

So all that happens is I get frustrated.

I have discovered that there are limits on some of the values you can use.

Sure I am learning from doing the reading etc…

But I feel it is not the “best” way to learn. There are limits to how much blood I can leave on the brick wall.

:wink:

But I feel it is not the "best" way to learn.

If you want someone else to look at the code, for you or with you, you need to be explicit about where you got the code. Unless it is a standard library, like SoftwareSerial, SoftPWM is not a standard library.

Expecting us to search for the library, download it, and read it for you is expecting a bit much, considering what we are paid to help.

Paul,

I am not wanting it to seem that what you said is my desire.

It isn't.

I am confused reading it and looked at where I got it and see there is/are no "instructions" other than those I have.

Alas in the mean time other problems have come up and now I have other things so my attention has been diverted to other more important things at this time.

When I get time again, I shall do more study of the code.