更新的代码我是 Python 新手,并试图让我的代码更高效。目前我正在将传感器值推送到 Firebase Realtime 数据库到不同的字段,但代码是重复的。无论如何我可以通过使用循环或替代方法来减小脚本的大小。
def getSound():
sound_value = grovepi.analogRead(sound_sensor)
result = firebase.patch('/SoundValues/Monday/'{'Sound1':int(sound_value)})
print("the sound value is%d" %sound_value)
time.sleep(1)
def getSound1():
sound_value = grovepi.analogRead(sound_sensor)
result = firebase.patch('/SoundValues/Monday/'{'Sound2':int(sound_value)})
print("the sound value is%d" %sound_value)
time.sleep(1)
任何帮助将不胜感激 :-)