Is it possible to control LED brightness using non PWM DIGITAL PINS?

Hello there,

I'm currently working on a project where when a switch is open (unpressed), LED-1 should be lit. When the same switch is closed (pressed), LED-1 will be lit BRIGHTER. Once the button is released the LED will go back to its original lit state. This can be easily achieved using PWM pins.

However, I need more PWM pins for the project I'm building that my board can provide. (Arduino Mega 1280 clone).

So my question is: Is it possible to control LED brightness using NON PWM DIGITAL PINS?

Thank you.

Sure. Use blink without delay. Monitor time passing with each pass thru loop, and when enough time passes then change the high/low state of the LED. If the button is pressed, turn the LED full on.

So: every pass thru loop, see of 2mS has passed. If it has and the switch is open, and the LED is off, then turn on the LED and vice versa;. 50% on time. It it has and the switch is closed, then turn the LED on and leave it on. 100% on time.

If the difference in brightness is not enough, then use 2mS on, 4mS off, or 2mS on, 6mS off.

You could try the SoftPWM library.

The SoftPWM is ment to be used with leds. It uses TIMER2 and I don't know if the SoftPWM is compatible with a Arduino Mega 1280.

Thank you all for your suggestions.

The SoftPWM Library route worked for me. Running a Gizduino X v2.0 (atMega 1281). Going to hook up around 20 LEDs. Will see how it fairs.