实验一:光控灯
代码:
/*!
* MindPlus
* mpython
*
*/
#include <MPython.h>
// 主程序开始
void setup() {
mPython.begin();
}
void loop() {
display.setCursorLine(1);
display.printLine((light.read()));
if (((light.read())<150)) {
rgb.write(-1, 0x0000FF);
display.setCursorLine(2);
display.printLine("天黑亮灯");
}
else {
rgb.write(-1, 0x000000);
display.setCursorLine(2);
display.printLine("天亮灯灭");
}
delay(3000);
}
结果截图:
实验二:声控灯
代码:
/*!
* MindPlus
* mpython
*
*/
#include <MPython.h>
// 主程序开始
void setup() {
mPython.begin();
}
void loop() {
display.setCursorLine(1);
display.printLine((light.read()));
if (((sound.read())>40)) {
rgb.write(-1, 0x0000FF);
display.setCursorLine(2);
display.printLine("灯亮");
delay(6000);
}
else {
rgb.write(-1, 0x000000);
display.setCursorLine(2);
display.printLine("灯灭");
}
delay(2000);
}
结果截图:
实验三:语音识别控制灯
代码:
j
iji结果截图:
实验四:实现Easy IoT上mqtt消息的通讯
甲按A键(或触摸P)发送消息至topic1,同时监听topic0
乙监听topic1,接收到甲的消息后按A(或触摸P)回复消息给topic0甲显示
代码:
结果截图: