Skip to content

Create an acceleration to LEDs example #65

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

Merged
merged 2 commits into from
Aug 8, 2019

Conversation

dcbriccetti
Copy link
Contributor

Inspired by circuitplayground_acceleration_neopixels.py, this example is more explicit about the mapping between acceleration values and color values. It constrains the absolute values of the inputs to standard gravity, then maps that range exactly onto 0–255. A comment in the code points to an explanatory video: https://youtu.be/eNpPLbYx-iA .

@caternuson caternuson requested a review from a team August 8, 2019 19:29
Copy link
Contributor

@kattni kattni left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this! I've made a few suggestions below.

return round(normalized_accel * 255) # Convert to 0–255


def fmt_accel(acceleration):
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use the full words here. It makes it longer, but clarity is more important.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

print('({}) ==> ({})'.format(fmt_accel(acceleration), fmt_rgb(rgb_amounts)))


def process():
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider removing this and instead simply include it's contents in the while True: loop. If you choose not to, I'd appreciate an explanation for choosing to include it in a function instead. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made the change you suggested. I did that to limit what’s put into the module scope.

This video walks you through the code: https://youtu.be/eNpPLbYx-iA
"""

from time import sleep
Copy link
Contributor

Choose a reason for hiding this comment

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

We try to avoid doing from foo import bar as it isn't as memory efficient as importing the lib alone and using it when needed. Please change this to import time and update the related code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting! Is this a CircuitPython peculiarity? I’d never heard of that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure, to be honest. We did a series of tests importing only the lib, importing individual parts of the lib using from, and doing from foo import *, and found the memory efficiency was best with importing the lib alone and then using it as needed. Something to do with the last two importing things before they're needed and using more memory, if I remember correctly.

return ', '.join(('{:>6.2f}'.format(axis_value) for axis_value in acceleration))


def fmt_rgb(rgb_amounts):
Copy link
Contributor

Choose a reason for hiding this comment

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

Forgot to include this one in the same way as the one before it - please use the full words here as well.

Copy link
Contributor

@kattni kattni left a comment

Choose a reason for hiding this comment

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

Thank you for making the changes! I really appreciate you submitting this example!

@kattni
Copy link
Contributor

kattni commented Aug 8, 2019

I will merge it as soon as the checks pass!

@dcbriccetti
Copy link
Contributor Author

Great! As I develop a sense for what would be useful, I will contribute more.

Thanks for the explanation about importing.

@kattni
Copy link
Contributor

kattni commented Aug 8, 2019

The checks failed, but it was a Travis issue. It never got to checking your code. I restarted the build. We'll see what happens.

@kattni kattni merged commit d16c916 into adafruit:master Aug 8, 2019
@dcbriccetti dcbriccetti deleted the accel-maps-pixels branch August 8, 2019 20:39
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Aug 9, 2019
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