Comments (3)
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.
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]
- 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.
- Just calls .duty(max_duty). Or .brightness(100).
- Shouldn't really have 'pwm' in the interface. Probably needs to take a float
- .duty(0)
But this is all off the top of my head, really need to experiment a little more...
from led_strip.
Class implementation has been resolved as at ef2ca57
from led_strip.
Related Issues (13)
- Debouncing needs to be handled HOT 1
- No silk screen annotations on connectors
- No LEDs on board
- Debounce resistors too high HOT 2
- Fade needs to be smoother HOT 3
- Add PIR to the system
- Need better control over LED strips on startup HOT 2
- Fade should look better for lower brightness settings HOT 1
- Pull-downs on FET driver lines required
- Only listen to rotary encoder when LED strip is on HOT 1
- Fades should be able to be interrupted HOT 3
- led_strip_breadboard.fzz: Unable to find part HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from led_strip.