Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

MakeCode accelerometer VS Circuit python
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

MakeCode accelerometer VS Circuit python

by Yalfmaster on Tue Oct 19, 2021 5:45 pm

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 !

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

Re: MakeCode accelerometer VS Circuit python

by mikeysklar on Thu Oct 21, 2021 5:44 pm

Which model accelerometer?

mikeysklar
 
Posts: 6212
Joined: Mon Aug 01, 2016 8:10 pm

Re: MakeCode accelerometer VS Circuit python

by Yalfmaster on Thu Oct 21, 2021 8:16 pm

The onboard one that come with the circuit playground express

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

Re: MakeCode accelerometer VS Circuit python

by mikeysklar on Fri Oct 22, 2021 3:19 pm

@Yalfmaster,

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

Code: Select all | TOGGLE FULL SIZE
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 | TOGGLE FULL SIZE
# 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 | TOGGLE FULL SIZE
from adafruit_circuitplayground import cp

cp.play_tone(440, 1)

mikeysklar
 
Posts: 6212
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.


cron