I'm having a hard time with this code:
Code
import serial
import time
import subprocess
ser=serial.Serial("/dev/ttyUSB0", 9600, timeout=30)
try:
while True:
if ser.isOpen():
cpu_temp=subprocess.getoutput("/opt/vc/bin/vcgencmd measure_temp" | "sed -e "s/temp=//" -e "s/\..*'/ /")
cpu_temp=int(cpu_temp.split(.)[0])
if cpu_temp < 40:
ser.write(b'pwm_000')
elif cpu_temp > 40 and cpu_temp < 50:
ser.write(b'pwm_025')
elif cpu_temp > 50 and cpu_temp < 65:
ser.write(b'pwm_050')
elif cpu_temp > 65 and cpu_temp < 75:
ser.write(b'pwm_075')
elif cpu_temp > 75:
ser.write(b'pwm_100')
except KeyboardInterrupt:
ser.write(b'pwm_000')
ser.close()
Display More
I'm pretty sure it's a formatting issue, but I can't seem to figure this part out:
Code
try:
while True:
if ser.isOpen():
cpu_temp=subprocess.getoutput("/opt/vc/bin/vcgencmd measure_temp" | "sed -e "s/temp=//" -e "s/\..*'/ /")
cpu_temp=int(cpu_temp.split(.)[0])
I keep getting errors, regardless of my changes. I get "unsupported operand type(s) for "|:" 'str' and 'str' " "syntax errors"
Honestly I can barely read this. Can someone please point me in the right direction?
Anything will help.
Thanks in advance!