Help! Adafruit Accelerometer - LED G-force

I’m creating my own DIY Project with the adafruit circuit board playground and the LEDs with alligator clips. I was able to code with “Make code” a way to have a scaling effect on my LEDs by tilting my circuit board. Is there any way to code a scaling effect with using g force instead of tilting. Please need help would be much appreciated.

Hi :slight_smile:

This is fairly simple actually - you just need to calculate the magnitude of the acceleration from the available x, y, and z components.

The formula is: sqrt(x^2+y^2+z^2)

Then just assign this to a variable in your code the same as before.

1 Like

I’m sorry for the inconvenience but I’m not the greatest or smartest when it comes to code. I don’t know where to input this, where in the coding would it go.

This is what I already have coded on my circuit board playground. where and what spot would the “sqrt(x^2+y^2+z^2) go”.

Eventually you’ll need it go in the strip.graph function: strip.graph(AccelMagnitude, GraphScale)

At the moment you’ve just got the component of acceleration in the x direction in there.

Checkout this reference page, particularly the section titled “Forces in Space”:

Hi @timothy138150 and welcome.

All the actions like tilting, shaking etc utilise the circuit playground’s onboard accelerometer. Just in different ways.

Adafruit has very good documentation on using Makeblocks and the Circuit Playground.

And for the accelerometer:

@Oliver33 reference is under these references.

1 Like

Thank you so much, i have a lot to learn and appreciate the information. I’m sure I’ll be back to ask more questions.

2 Likes

@Oliver33 @Robin57159 I apologize for bothering you but I am still having trouble trying to code the g-force as a graph on a LED light using the (Circuitboard Playground). Are there any videos that are more in-depth on this subject?

Hey Timothy,

No worries, everyone here is here to help! We’ve got a few tutorials on using accelerometers with CircuitPython that you can find below. If you’d like us to go over your code please use ``` around it and you can put it up in this forum (also Stack Overflow would be a great place for debugging too, but tends to be focused directly on the code)

Please let us know if there’s anything else that we can help you with!

Bryce
Core Electronics | Support

I appreciate the help, when it comes to coding I’m way before a beginner so all this is very new to me.

1 Like

No worries Timothy,

Glad I could help, have a great day!

Bryce
Core Electronics | Support

Hi @timothy138150

To control the brightness of the LED on a pin you need to configure the pin to use pulse width modulation (PWM) using the analogSetPeriod block. The value read from the accelerometer is passed into this. Pins A1, A2, or A3 are probably easiest to use and leave most other pins free for other uses.

Refer to the docs here: