从可以在另一个函数中使用的函数传递返回的数据时遇到问题。这是我写的原始代码,它工作正常,但我想将其中的一些添加到函数中。 https://github.com/Octane70/Code/blob/master/Rouge/rouge2_main.py
以下是我想添加功能的代码部分。 data_received(数据)功能是从蓝牙服务器中提取数据 我已经运行了,我想将数据传递给我创建的两个函数。 我得到一个错误,"数据"未在command = data_received(数据)行上定义。任何帮助,将不胜感激。感谢?
def data_received(data):
get_data1 = get_data2(data)
return get_data1
command = data_received(data)
def auto_manual(command):
if command == "9":
GPIO.output(26, True)
GPIO.output(16, False)
#manual_mode
#auto_mode.exit()
print ("Green On")
elif command == "11":
GPIO.output(16, True)
GPIO.output(26, False)
#autoMode
#manual_mode.terminate()
print ("Blue On")
def manual_mode(command):
#Dpad Forward
if command == "1":
rouge2_manual.Forward()
elif command == "2":
rouge2_manual.Stop()
#Dpad Reverse
elif command == "3":
rouge2_manual.Reverse()
elif command == "4":
rouge2_manual.Stop()
#Dpad Left
elif command == "5":
rouge2_manual.Left()
elif command == "6":
rouge2_manual.Stop()
#Dpad Right
elif command == "7":
rouge2_manual.Right()
elif command == "8":
rouge2_manual.Stop()
BluetoothServer(data_received)
答案 0 :(得分:0)
我能够解决我的问题,谢谢:
def data_received(data):
auto_manual(data)
manual_mode(data)
def auto_manual(command):
if command == "9":
GPIO.output(26, True)
GPIO.output(16, False)
#manual_mode
#auto_mode.exit()
print ("Green On")
elif command == "11":
GPIO.output(16, True)
GPIO.output(26, False)
#autoMode
#manual_mode.terminate()
print ("Blue On")
def manual_mode(command):
#Dpad Forward
if command == "1":
rouge2_manual.Forward()
elif command == "2":
rouge2_manual.Stop()
#Dpad Reverse
elif command == "3":
rouge2_manual.Reverse()
elif command == "4":
rouge2_manual.Stop()
#Dpad Left
elif command == "5":
rouge2_manual.Left()
elif command == "6":
rouge2_manual.Stop()
#Dpad Right
elif command == "7":
rouge2_manual.Right()
elif command == "8":
rouge2_manual.Stop()
BluetoothServer(data_received)
pause()