Giter Site home page Giter Site logo

Comments (3)

HowManyOliversAreThere avatar HowManyOliversAreThere commented on July 21, 2024

Possible example of class usage:

import led_strip
my_led_strip = led_strip(7) # LED strip driver connected to pin 7
my_led_strip.on() # turns theLED strip to full brightness
my_led_strip.pwm(70) # pulses the LED strip at 70% of the maximum PWM
print('PWM value: %i' % my_led_strip.getPwm()) # prints the current PWM value (0 for off, 100 for fully on)
my_led_strip.off() # turns the LED strip off

Could possibly also have increment and decrement functions that increase of decrease the pwm by a fixed amount, amount settable by a setIncrements(incrementSize) function

from led_strip.

mattytrentini avatar mattytrentini commented on July 21, 2024

Agree with pulling the need to encapsulate the led strip functionality. And yes, some thought will need to be given to how to fade and debounce nicely, I'm leaning toward a design based around asyncio. This example is close to what I'm thinking (though we'd use PWM support rather than do it manually).

As for the interface, you've made a good start though a couple of changes have popped out:

from machine import PWM, Pin 
import led_strip
my_led_strip = led_strip(machine.PWM(machine.Pin(7), freq=1000), max_duty=1023) # [1]
my_led_strip.on() # turns the LED strip to full brightness [2]
my_led_strip.brightness(70) # Set the strip to a percentage of maximum brightness [3]
print('Brightness: %i' % my_led_strip.brightness) # prints the current brightness value
my_led_strip.off() # turns the LED strip off [4]
  1. I think we should just expect an object to be passed in that provides a 'duty' method rather than doing all the GPIO management internally. This makes it more composable and portable.
  2. Just calls .duty(max_duty). Or .brightness(100).
  3. Shouldn't really have 'pwm' in the interface. Probably needs to take a float
  4. .duty(0)

But this is all off the top of my head, really need to experiment a little more...

from led_strip.

HowManyOliversAreThere avatar HowManyOliversAreThere commented on July 21, 2024

Class implementation has been resolved as at ef2ca57

from led_strip.

Related Issues (13)

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.