code.py
1 # SPDX-FileCopyrightText: 2020 Bryan Siepert for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 import puff_detector 6 7 detector = puff_detector.PuffDetector() 8 9 10 @detector.on_sip 11 def on_sip(strength, duration): 12 if strength == puff_detector.STRONG: 13 strength_str = "STRONG" 14 if strength == puff_detector.SOFT: 15 strength_str = "SOFT" 16 log_str = "DETECTED::SIP:%s::DURATION:%0.3f" % (strength_str, duration) 17 print(log_str) 18 19 20 @detector.on_puff 21 def on_puff(strength, duration): 22 if strength == puff_detector.STRONG: 23 strength_str = "STRONG" 24 if strength == puff_detector.SOFT: 25 strength_str = "SOFT" 26 log_str = "DETECTED::PUFF:%s::DURATION:%0.3f" % (strength_str, duration) 27 print(log_str) 28 29 30 detector.run()