-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add RGB pulse function #15
Conversation
}, | ||
// state.prev records the last color set using color(), | ||
// and is used to determine the new color when calling on() or pulse() | ||
prev: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state.prev
was added in prior implementation as well. @islemaster adeptly explains the reasoning for this addition here.
// uses state.prev for the current color | ||
pulse(duration, callback) { | ||
const state = priv.get(this); | ||
var currentColor = state.prev; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pulse()
uses the last color set using color()
, saved to state.prev
instead of checking the actual current color of the RGB as done in the prior implementation of pulse()
. This is to avoid a problem where subsequent calls to pulse
would lead to smaller and smaller intensity ranges. @islemaster gives an example of this case here.
pulse(duration, callback) { | ||
const state = priv.get(this); | ||
var currentColor = state.prev; | ||
this.stop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc for segment properties.
…reuse Animation.keys
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Now that the code-dot-org/johnny-five is updated to the latest release from upstream, this PR re-implements the
rgb.pulse
function in theRGB
class. Refer to this PR for the past implementation of this function.The implementation of pulse was very similar to past implementation by @islemaster. However I kept the upstream implementation of
Animation.render
inrgb.js
.Also, in
rgb.js
I had to move the assignment of Animation.keys after RGB.colors was defined. When I first implemented thepulse
function, I received an error due to the fact thatAnimation.keys
was not defined correctly.Looking in
rgb.js
, the reason was thatRGB.colors
was not assigned yet. So I placed theRGB.colors
assignment before theAnimation.keys
was assigned to it. I also added clarifying comments in thetweenedValues
function where an error was being thrown before the fix.Comments are embedded for more details of implementation.
Links
jira - Re-add LED pulse to johnny-five
Testing
I ran the johnny-five tests locally using
grunt
:I also tested locally with the Circuit Playground. Videos are below.
This is a program that toggles between
rgb.pulse
andrgb.blink
:pulse.and.blink.mp4
This is a program that shows both 'rgb.pulse
and
led.pulse`:compare.led.and.rgb.pulse.mp4