【发布时间】:2019-12-03 19:06:08
【问题描述】:
我目前正在做一个 arduino 项目。 arduino 是否通过 Web 套接字与 NodeJS 服务器通信。
套接字连接工作正常,没有问题。但我目前遇到的问题是,我希望能够使用来自 NodeJS 服务器的套接字发出来中断无限循环。
我发现一个页面可以解决这个问题,但只有一个按钮连接到 arduino。
Link to page (Interrupt with button)
这是我希望能够用套接字中断的循环:
bool loopRunning = true;
void rainbow(int wait) {
while(loopRunning == true) {
for(long firstPixelHue = 0; firstPixelHue < 3*65536; firstPixelHue += 256) {
for(int i=0; i<strip.numPixels(); i++) {
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
}
strip.show();
delay(wait);
}
}
}
我想在收到套接字发出时将 loopRunning 设置为 false。
任何人有任何想法我可以如何实现这一点?
【问题讨论】:
标签: socket.io interrupt nodemcu neopixel