Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulse Width Modulation #7

Closed
SteveDesmond-ca opened this issue Jul 25, 2018 · 4 comments
Closed

Pulse Width Modulation #7

SteveDesmond-ca opened this issue Jul 25, 2018 · 4 comments
Labels
feature Additional or changing functionality

Comments

@SteveDesmond-ca
Copy link
Member

Being able to dim / slow components would be cool. I have no idea how to go about doing it.

@SteveDesmond-ca
Copy link
Member Author

@chris-castillo
Copy link

I can work on this if this project is still in development?

@SteveDesmond-ca SteveDesmond-ca added the feature Additional or changing functionality label Nov 24, 2021
@SteveDesmond-ca
Copy link
Member Author

The .NET IOT device bindings library has a software PWM implementation that we can wrap.

A quick demo found that the high precision setting is needed for smooth (aka not stepped) transitions and to prevent flickering, but this pins a high priority thread at 100%. That means full RGB LED control would use 75% of a Raspberry Pi's CPU.

60Hz seems acceptable from a visual standpoint, though we may want to double that to 120Hz for those with acute vision, if going with high precision; without high precision, 120Hz flickers.

using System.Device.Pwm.Drivers;

var running = true;

var pwm = new SoftwarePwmChannel(26, 1, 0, true);
pwm.Start();

while (running)
{
	var key = Console.ReadKey();
	switch (key.Key)
	{
		case ConsoleKey.UpArrow:
			pwm.DutyCycle += 0.01;
			break;
		case ConsoleKey.DownArrow:
			pwm.DutyCycle -= 0.01;
			break;
		case ConsoleKey.RightArrow:
			pwm.Frequency += 1;
			break;
		case ConsoleKey.LeftArrow:
			pwm.Frequency -= 1;
			break;
		case ConsoleKey.Q:
			running = false;
			break;
	}

	Console.WriteLine($"On: {pwm.DutyCycle:P0} % / Freq: {pwm.Frequency,10} Hz");
}

pwm.Stop();
Console.WriteLine("Done!");
pwm.Dispose();

@SteveDesmond-ca
Copy link
Member Author

Implemented in v2.0-beta.2 via IPinInterface.Strength -- docs and helpers coming by v2.0 final

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Additional or changing functionality
Projects
None yet
Development

No branches or pull requests

2 participants