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

Add RGB pulse function #15

Merged
merged 4 commits into from
Oct 14, 2022
Merged

Add RGB pulse function #15

merged 4 commits into from
Oct 14, 2022

Conversation

fisher-alice
Copy link

@fisher-alice fisher-alice commented Oct 13, 2022

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 the RGB 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 in rgb.js.
Also, in rgb.js I had to move the assignment of Animation.keys after RGB.colors was defined. When I first implemented the pulse function, I received an error due to the fact that Animation.keys was not defined correctly.
Looking in rgb.js, the reason was that RGB.colors was not assigned yet. So I placed the RGB.colors assignment before the Animation.keys was assigned to it. I also added clarifying comments in the tweenedValues 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:

Screen Shot 2022-10-14 at 2 05 56 PM

I also tested locally with the Circuit Playground. Videos are below.
This is a program that toggles between rgb.pulse and rgb.blink:

pulse.and.blink.mp4

This is a program that shows both 'rgb.pulseandled.pulse`:

compare.led.and.rgb.pulse.mp4

@fisher-alice fisher-alice marked this pull request as ready for review October 13, 2022 18:38
},
// state.prev records the last color set using color(),
// and is used to determine the new color when calling on() or pulse()
prev: {
Copy link
Author

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;
Copy link
Author

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();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc for segment properties.

@fisher-alice fisher-alice requested review from a team and epeach October 13, 2022 19:33
Copy link

@sanchitmalhotra126 sanchitmalhotra126 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

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

Successfully merging this pull request may close these issues.

2 participants