MakeCode accelerometer VS Circuit python

Play with it! Please tell us which board you're using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Yalfmaster
 
Posts: 11
Joined: Sun Apr 02, 2017 4:58 am

MakeCode accelerometer VS Circuit python

Post by Yalfmaster »

Hi, my project is to merge 2 ideas, I manage to make a custom sound from the buzzer through Circuit python.
The other idea is that I want to trigger this sound when the accelerometer sense more than 8g on the X axis (I succeed with MakeCode but I can't use custom .wav sound)
Does anyone could help me the use the same 8g (or more) trigger but in Circuit python ?
Thanks for the support !

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: MakeCode accelerometer VS Circuit python

Post by mikeysklar »

Which model accelerometer?

User avatar
Yalfmaster
 
Posts: 11
Joined: Sun Apr 02, 2017 4:58 am

Re: MakeCode accelerometer VS Circuit python

Post by Yalfmaster »

The onboard one that come with the circuit playground express

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: MakeCode accelerometer VS Circuit python

Post by mikeysklar »

@Yalfmaster,

You can use cp.acceleration as the value to determine when to trigger the buzzer.

Code: Select all

from adafruit_circuitplayground import cp

while True:
    x, y, z = cp.acceleration
    print(x, y, z)
https://circuitpython.readthedocs.io/pr ... nd-express

You can follow this more lengthy example swapping out the cp.pixels.fill() for cp.play_tone().

Code: Select all

# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

"""If the switch is to the right, it will appear that nothing is happening. Move the switch to the
left to see the NeoPixels light up in colors related to the accelerometer! The Circuit Playground
has an accelerometer in the center that returns (x, y, z) acceleration values. This program uses
those values to light up the NeoPixels based on those acceleration values."""
from adafruit_circuitplayground import cp

# Main loop gets x, y and z axis acceleration, prints the values, and turns on
# red, green and blue, at levels related to the x, y and z values.
while True:
    if not cp.switch:
        # If the switch is to the right, it returns False!
        print("Slide switch off!")
        cp.pixels.fill((0, 0, 0))
        continue
    R = 0
    G = 0
    B = 0
    x, y, z = cp.acceleration
    print((x, y, z))
    cp.pixels.fill(((R + abs(int(x))), (G + abs(int(y))), (B + abs(int(z)))))
https://learn.adafruit.com/circuitpytho ... celeration

Code: Select all

from adafruit_circuitplayground import cp

cp.play_tone(440, 1)

Locked
Please be positive and constructive with your questions and comments.

Return to “Circuit Playground Classic, Circuit Playground Express, Circuit Playground Bluefruit”