-
Notifications
You must be signed in to change notification settings - Fork 71
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
Conversation
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.
Thanks for submitting this! I've made a few suggestions below.
return round(normalized_accel * 255) # Convert to 0–255 | ||
|
||
|
||
def fmt_accel(acceleration): |
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.
Please use the full words here. It makes it longer, but clarity is more important.
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.
Sure
print('({}) ==> ({})'.format(fmt_accel(acceleration), fmt_rgb(rgb_amounts))) | ||
|
||
|
||
def process(): |
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.
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!
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.
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 |
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.
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.
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.
Interesting! Is this a CircuitPython peculiarity? I’d never heard of that.
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.
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): |
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.
Forgot to include this one in the same way as the one before it - please use the full words here as well.
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.
Thank you for making the changes! I really appreciate you submitting this example!
I will merge it as soon as the checks pass! |
Great! As I develop a sense for what would be useful, I will contribute more. Thanks for the explanation about importing. |
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. |
Updating https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground to 2.1.2 from 2.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_CircuitPlayground#65 from dcbriccetti/accel-maps-pixels Updating https://github.com/adafruit/Adafruit_CircuitPython_ST7789 to 1.1.0 from 1.0.2: > Merge pull request adafruit/Adafruit_CircuitPython_ST7789#5 from makermelissa/master
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 .