カメラで撮影と同時にLEDを点灯させるようにしたいのですが、時間を測定していると微妙に時間がずれてしまってます。
何秒後に撮影、点灯といったことを正確な時間で行うことはできないのでしょうか。
python
1import time 2import picamera 3import threading 4import RPi.GPIO as GPIO 5 6GPIO.setmode(GPIO.BOARD) 7GPIO.setup(11,GPIO.OUT) 8 9starttime = time.perf_counter() 10 11def camera(): 12 global ctime 13 with picamera.PiCamera() as camera: 14 camera.resolution = (640,480) 15 time.sleep(1) 16 camera.capture('/home/pi/cameradata/image.jpg') 17 cameratime = time.perf_counter() 18 ctime = cameratime - starttime 19 print("CAM = {:.9f}s" .format(ctime)) 20 camera.stop_preview() 21 22def LED(): 23 global Ltime 24 25 for i in range(1): 26 GPIO.output(11,GPIO.LOW) 27 time.sleep(1) 28 GPIO.output(11,GPIO.HIGH) 29 LEDtime = time.perf_counter() 30 Ltime = LEDtime - starttime 31 print("LED = {:.9f}s" .format(Ltime)) 32 time.sleep(0.01) 33 GPIO.output(11,GPIO.LOW) 34 time.sleep(2) 35 36 GPIO.cleanup() 37 38 39p1 = threading.Thread(target = camera) 40p2 = threading.Thread(target = LED) 41 42p1.start() 43p2.start() 44p1.join() 45p2.join()