I'm coding so that the LED is turned on at Arduino with Python.
It's coded to respond to clapping at once, but the problem is that if you do this, it responds to other noises.
So I want to respond to a specific clap pattern (I'm going to clap easily), but it's unfamiliar and I don't have a clue. How should I do it?
from machine import Pin
from time import sleep
led = Pin(13, Pin.OUT)
sound = Pin(12, Pin.IN)
wait = 0.1
state = 0
while True:
if sound.value() ==1:
state = 1 - state
print(sound.value(), state)
led.value(state)
sleep(wait)
It's a code that responds with one clap.
python arduino
If the sensor has a sound value of 0 and 1,
// default wait status
//if (sound.value() == 1)
// As long as you want to clap, wait
//(ex, wait 0.5 seconds. If you don't do it in 1 second, break to the default wait;)
//if(sound.value() == 1)
// Desired behavior (ex, led on)
How about this?
© 2024 OneMinuteCode. All rights reserved.