But
I have a small module designed for making props. It has motion sensors on it, powers LEDs, makes sounds, that sort of thing. It also has a feature where you can have one of the led pins try to emulate whatever the sound is doing by producing a PWM. The idea being that on LED can pulse with an intensity relative to the sound, though not the volume of the sound. I think it's based on the actual analog data (or wave forms, I'm not sure which term is appropriate here) so that volume is irrelevant.
I had a project going on an Arduino and I was using pulseIn to read the pwm, and then take that number and do stuff with it. In general, I would get a range of values between 0-27, the higher values consistently popping up whenever I would do something that would produce a more intense sound.
Code: Select all
byte PWM_PIN = 6; //PWM is coming in here
void setup() {
pinMode(PWM_PIN, INPUT);
}
void loop() {
pulse = pulseIn(PWM_PIN, HIGH, 100);
Serial.println(pulse);
delay(5);
}
I recently ported the project over to circuitpython on an itsy bitsy m4 express. Reading the documentation for pulseIn, it seems like it's expected to work Identically. That being said, for some reason circuitpython is only returning values 27-28, and not a fluctuation of the two, when I turn everything on, it starts at 0, rapidly ramps to either 27 or 28 and then stays there.
Code: Select all
import board
import time
import pulseio
pulse_in = pulseio.PulseIn(board.D13, maxlen=1, idle_state=True)
while True:
print(pulse_in[0])
time.sleep(0.05)
Just in case I had somehow ruined something, I connected it back to the arduino and ran a test with the old code, but it only acted how I expected it to, producing a variation of numbers between 0-27-ish based on what the sound was doing. So it's not my hardware, at least on the module/arduino end of things. Not to say it's the M4. It's likely my code, but I'm not certain what I'm doing wrong.
The only circuitpython tutorial I could find that involved pulseIn was the IR remote one, but unfortunately, reading through that didn't help much.
I also keep gett
"IndexError: PulseIn index out of range"
but I'm only ever storing one value, so calling to the first slot should never be out of range, right?
I'm going to keep reading through the documentation to see if I missed anything, but feel free to tell me the things I'm doing wrong.
I just want read one number at a time and do something based on that number, so I really don't need to store more than one.