Giter Site home page Giter Site logo

Comments (4)

chris-castillo avatar chris-castillo commented on June 12, 2024 1

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

from simplegpio.

SteveDesmond-ca avatar SteveDesmond-ca commented on June 12, 2024

Gross. Literally just toggling really fast. https://github.com/larsks/raspberry-gpio-python-code/blob/6d62222bd5384eb2dc2ed13065ea28dcb506cc67/source/soft_pwm.c#L90-L114

from simplegpio.

SteveDesmond-ca avatar SteveDesmond-ca commented on June 12, 2024

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();

from simplegpio.

SteveDesmond-ca avatar SteveDesmond-ca commented on June 12, 2024

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

from simplegpio.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.