问题描述
import time
import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(23 , GPIO.IN)
while True:
if GPIO.input(23)==1:
os.system('raspistill -o image.jpg')
os.system(‘gpicview image.jpg &’)
sleep(20)
os.system(‘killall gpicview’)
else:
print "Ready to take picture"
GPIO.cleanup()
亲爱的朋友,我正在尝试通过按钮控制覆盆子picamera.就像我按下按钮时,它应该拍照.当我按下按钮时,我也将GPIO引脚配置为按钮,但是按钮却无法正常工作,但是picamera会自己拍照.我如何使其与按钮一起使用? python上的任何专家都可以指导我吗?谢谢!
Dear friends I'm trying to control raspberry picamera with a button.. like when i press the button it should take a picture. I configured GPIO pins also button when I press button nothing is working, however picamera taking photo itself. How can i make it work with button? any experts on python can guide me? thanks!
推荐答案
硬件不能给我们干净的1或0,它会来回反弹.检查此代码以反跳"该按钮:
Hardware doesn't give us a clean 1 or 0, it bounces back and forth a bit. Check this code for "debouncing" the button:
https://www.cl.cam.ac .uk/projects/raspberrypi/tutorials/robot/buttons_and_switches/
这篇关于使用GPIO通过按钮控制覆盆子picamera的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!