Breathing ledborg

Forums:

Would it be possible to make the led 'breath' by doing some type of pwm? Would I have to hack the driver?

Or is it just not possible?

-Andy

piborg's picture

It is possible using PWMs, the problem with the driver is the mechanism it uses to get a regular interval execution only gets called every 10ms, and therefore slow enough to see the led flash.

I have uploaded an example based on the basic driver source which will run in userspace and ramp the brightness level of the red LED up and down at a somewhat regular interval, the only catch is when the processor is busy the LED is likely to 'flicker'
Download here: http://www.piborg.org/downloads/ledborg/source-pulse.zip
If you have already installed the driver you will need to disable it when running this as well.
You will need to run the program as a superuser e.g.
sudo /etc/init.d/ledborg.sh stop
mkdir ~/ledborg-pulse
cd ~/ledborg-pulse
wget -O source.zip http://www.piborg.org/downloads/ledborg/source-pulse.zip
unzip source.zip
make
sudo ./ledborg-pulse

That is just what I meant - now I will tinker and report back :)

I set up wiringpi on my machine and made this work with ledborg - now to make a color mixer...

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>

#include <wiringPi.h>
#include <softPwm.h>

#define constrain(amt,low,high) ((amt)<(low) ? (low) : ((amt)>(high) ? (high) : (amt)))

#define RANGE           100
#define NUM_LEDS         3

int ledMap [NUM_LEDS] = { 0, 3, 2 };

int values [NUM_LEDS] = { 0, 17, 32 };


int main ()
{

	if (wiringPiSetup () == -1) {
		fprintf (stdout, "oops: %s\n", strerror (errno));
		return 1;
	}

	softPwmCreate(3,0,255); //setup software pwm pin
	int i = 0;
	// bring the LED up nicely from being off
	for (i = 0; i <= 15; i += 1) {
		softPwmWrite(3, i);
		delay(100);
	}
	while (1) {
		for (i = 15; i <= 255; i += 1) {
			softPwmWrite(3, i);
			if (i > 150) {
				delay(4);
			}
			if ((i > 125) && (i < 151)) {
				delay(5);
			}
			if (( i > 100) && (i < 126)) {
				delay(7);
			}
			if (( i > 75) && (i < 101)) {
				delay(10);
			}
			if (( i > 50) && (i < 76)) {
				delay(14);
			}
			if (( i > 25) && (i < 51)) {
				delay(18);
			}
			if (( i > 1) && (i < 26)) {
				delay(19);
			}
		}
		for (i = 255; i >=15; i -= 1) {
			softPwmWrite(3, i);
			if (i > 150) {
				delay(4);
			}
			if ((i > 125) && (i < 151)) {
				delay(5);
			}
			if (( i > 100) && (i < 126)) {
				delay(7);
			}
			if (( i > 75) && (i < 101)) {
				delay(10);
			}
			if (( i > 50) && (i < 76)) {
				delay(14);
			}
			if (( i > 25) && (i < 51)) {
				delay(18);
			}
			if (( i > 1) && (i < 26)) {
				delay(19);
			}
		}
		delay(970);
	}

}
Timothy Freeburn's picture

That's fantastic :) Do you have any videos of it pulsing online?

Timothy Freeburn's picture

Above code edited to use <pre></pre>

Subscribe to Comments for &quot;Breathing ledborg&quot;