プログラム初心者です。
ラズパイにセンサーをつないで遊んでいます。
サンプルとして用意されていたコードが
python2ではそのまま動くのですが
python3では動きませんでした。
python3で動かしたいと思っているのですが、
#!/usr/bin/env python
import RPi.GPIO as GPIO
import ADC0832
import time
LedPin = 16
threshold = 120
def init():
ADC0832.setup()
GPIO.setup(LedPin, GPIO.OUT)
def loop():
while True:
res = ADC0832.getResult(0)
print ('res = %d') % res
if(res > threshold):
print ('It is night, light on...')
GPIO.output(LedPin, GPIO.HIGH)
else:
print ('It is already dawn, light off')
GPIO.output(LedPin, GPIO.LOW)
time.sleep(0.2)
if name == 'main':
init()
try:
loop()
except KeyboardInterrupt:
ADC0832.destroy()
print 'The end !'
python3で動かしてみたところ、
下記のアラートが出ました。
Traceback (most recent call last):
File "/home/pi/Desktop/Python保存/photoresistor/ees.py", line 32, in <module>
loop()
File "/home/pi/Desktop/Python保存/photoresistor/ees.py", line 19, in loop
print ('res = %d') % res
TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'
どのように修正したらアラートが表示されなくなるのでしょうか。
回答2件
あなたの回答
tips
プレビュー