ラズパイに接続した温度計から数値をprintすることはできたのですが、
この数値をprintではなくべつの.pyでインポートして読み込みたいのですが
関数と引数の渡し方がわかりません。
どのようにすれば、渡すことができますか?
tem.py
python
1import os 2import time 3 4 5def readSensor(id): 6 7 tfile = open("/sys/bus/w1/devices/"+id+"/w1_slave") 8 text = tfile.read() 9 tfile.close() 10 secondline = text.split("\n")[1] 11 temperaturedata = secondline.split(" ")[9] 12 temperature = float(temperaturedata[2:]) 13 temperature = temperature / 1000 14 print(temperature)#←temperatureをtem2.pyで読み込みたい 15 16print(readSensor()) 17 18def readSensors(): 19 count = 0 20 for file in os.listdir("/sys/bus/w1/devices/"): 21 #print(file) 22 if (file.startswith("28-")): 23 readSensor(file) 24 count+=1 25 26 if (count == 0): 27 print("No sensor found! Check connection") 28 29def loop(): 30 while True: 31 readSensors() 32 time.sleep(1) 33 34def destroy(): 35 pass 36 37if __name__ == "__main__": 38 try: 39 loop() 40 except KeyboardInterrupt: 41 destroy()
tem2.py
python
1import tem 2 3if temperature>10: 4 print("ON") 5else: 6 print("OFF") 7#のようなことを実現したいです 8
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。