I am a beginner and
I want to make play control system by using pressure sensor.
In general situation, only sample1 video is played but
If someone sit on the chair, which is built pressure sensor, play sample2 video.
To make this system, I built below code, but when I run the code, only sample1 video was played for a second, and suddenly my
RPI is shutdown. How can I fix this problem? If you have any suggestions, I would greatly appreciate it! Thanks!
Code: Select all
import spidev, time, sys, os
from subprocess import Popen
import subprocess as sp
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 1000000
def analog_read(channel):
r = spi.xfer2([1, (0x08 + channel) << 4, 0])
adc_out = ((r[1]&0x03) << 8) + r[2]
return adc_out
video1 = ('/home/pi/Videos/sample1.mp4')
video2 = ('/home/pi/Videos/sample2.mp4')
while True:
reading = analog_read(1)
time.sleep(1)
if (reading <= 20):
zone = 1
elif (reading > 20):
zone = 2
if (zone == 1):
Popen(['omxplayer', '-b', video1])
if (zone == 2):
Popen(['omxplayer', '-b', video2])