Created
November 4, 2023 18:35
-
-
Save lizzybrooks/81ed271a5886c5b01d6a4b4376f3f24c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import board | |
import pulseio | |
import time | |
pulses = pulseio.PulseIn(board.A0, maxlen=200, idle_state=True) | |
lightCounter = 0 | |
while True: | |
# Wait for an active pulse | |
while len(pulses) == 0: | |
pass | |
# Pause while we do something with the pulses | |
pulses.pause() | |
# Print the pulses. pulses[0] is an active pulse unless the length | |
# reached max length and idle pulses are recorded. | |
print("got pulse") | |
lightCounter +=1 | |
print(lightCounter) | |
for n in range(0,len(pulses),1): | |
print(pulses[n]) | |
time.sleep(.4) | |
# Clear the rest | |
pulses.clear() | |
print("cleared pulses") | |
print(len(pulses)) | |
# Resume with an 80 microsecond active pulse | |
pulses.resume(80) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment