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 !
MakeCode accelerometer VS Circuit python
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: MakeCode accelerometer VS Circuit python
Which model accelerometer?
- Yalfmaster
- Posts: 11
- Joined: Sun Apr 02, 2017 4:58 am
Re: MakeCode accelerometer VS Circuit python
The onboard one that come with the circuit playground express
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: MakeCode accelerometer VS Circuit python
@Yalfmaster,
You can use cp.acceleration as the value to determine when to trigger the buzzer.
https://circuitpython.readthedocs.io/pr ... nd-express
You can follow this more lengthy example swapping out the cp.pixels.fill() for cp.play_tone().
https://learn.adafruit.com/circuitpytho ... celeration
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)
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)))))
Code: Select all
from adafruit_circuitplayground import cp
cp.play_tone(440, 1)
Please be positive and constructive with your questions and comments.