我正在使用互联网按钮进行粒子项目,以及python中的程序。我如何组合我的粒子代码,以便python代码然后运行粒子代码,什么是组合它们的最佳方式?
#include <Arduino.h>
#include <InternetButton.h>
InternetButton button = InternetButton();
bool rainbow_mode = false;
int buzzer = D0;
void setup() {
button.begin();
pinMode(buzzer, OUTPUT);
}
void loop() {
if (button.allButtonsOff()) {
button.rainbow(5);
}
if (button.buttonOn(1)) {
button.allLedsOff();
tone(buzzer, 2000, 500);
delay(1000);
}
}
我的代码在python:
def on_message(ws, message):
global KETTLEIP
global LIGHTIP
global MACADDRESS
print (message)
#tweet(message)
if (message == "kettle"):
if kettle_ip.exists():
file = open("ketIP", "r")
data = file.read()
ket.setOn(data)
elif ("lights" in message and "on" in message):
light.setAll(LIGHTIP)
elif ("lights" in message and "off" in message):
light.setOff(LIGHTIP)
def on_error(ws, error):
print (error)
def on_close(ws):
print ("### closed ###")
def on_open(ws):
print ('Opening Websocket connection to the server ... ')
if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.WebSocketApp("ws://",
on_open=on_open,
on_message=on_message,
on_error=on_error,
on_close=on_close,
)
ws.on_open = on_open
ws.run_forever()
我想做的是,灯亮,然后运行粒子上的代码