/*!
* MindPlus
* mpython
*
*/
#include <MPython.h>
#include <SimpleList.h>
#include <DFRobot_Iot.h>
#include <DFRobot_Task.h>
#include <DFRobot_HuskyLens.h>
#include<DFRobot_SpeechSynthesis.h>
// 动态变量
String mind_s_MingZi;
volatile float mind_n_ZiXianCheng8ShiJian, mind_n_ZiXianCheng7ShiJian, mind_n_ZiXianCheng6ShiJian,
mind_n_ZiXianCheng5ShiJian, mind_n_ZiXianCheng4ShiJian, mind_n_ZiXianCheng3ShiJian,
mind_n_ZiXianCheng2ShiJian, mind_n_ZiXianCheng1ShiJian, mind_n_YiQiDongZiXianChengGeShu;
SimpleList<String> mind_l_RenMing, mind_l_ZhiXingRenMing, mind_l_ZhiXingZiXianChengDaiMa;
// 函数声明
void onButtonAPressed();
void onButtonBPressed();
void DF_ChuShiHua();
void DF_HuoQuShiJian(String mind_s_MingZi);
newTask(loop8)
newTask(loop7)
newTask(loop6)
newTask(loop5)
newTask(loop4)
newTask(loop3)
newTask(loop2)
newTask(loop1)
// 静态常量
const String topics[5] = {"w9QhgiXGg","","","",""};
// 创建对象
DFRobot_SpeechSynthesis_I2C sstts;
DFRobot_HuskyLens huskylens;
DFRobot_Iot myIot;
// 主程序开始
void setup() {
mPython.begin();
buttonA.setPressedCallback(onButtonAPressed);
buttonB.setPressedCallback(onButtonBPressed);
sstts.begin();
DF_ChuShiHua();
}
void loop() {
}
// 子线程8程序开始
void loop8::setup() {
mind_n_ZiXianCheng8ShiJian = 0;
}
void loop8::loop() {
delay(60000);
mind_n_ZiXianCheng8ShiJian += 1;
}
// 子线程7程序开始
void loop7::setup() {
mind_n_ZiXianCheng7ShiJian = 0;
}
void loop7::loop() {
delay(60000);
mind_n_ZiXianCheng7ShiJian += 1;
}
// 子线程6程序开始
void loop6::setup() {
mind_n_ZiXianCheng6ShiJian = 0;
}
void loop6::loop() {
delay(60000);
mind_n_ZiXianCheng6ShiJian += 1;
}
// 子线程5程序开始
void loop5::setup() {
mind_n_ZiXianCheng5ShiJian = 0;
}
void loop5::loop() {
delay(60000);
mind_n_ZiXianCheng5ShiJian += 1;
}
// 子线程4程序开始
void loop4::setup() {
mind_n_ZiXianCheng4ShiJian = 0;
}
void loop4::loop() {
delay(60000);
mind_n_ZiXianCheng4ShiJian += 1;
}
// 子线程3程序开始
void loop3::setup() {
mind_n_ZiXianCheng3ShiJian = 0;
}
void loop3::loop() {
delay(60000);
mind_n_ZiXianCheng3ShiJian += 1;
}
// 子线程2程序开始
void loop2::setup() {
mind_n_ZiXianCheng2ShiJian = 0;
}
void loop2::loop() {
delay(60000);
mind_n_ZiXianCheng2ShiJian += 1;
}
// 子线程1程序开始
void loop1::setup() {
mind_n_ZiXianCheng1ShiJian = 0;
}
void loop1::loop() {
delay(60000);
mind_n_ZiXianCheng1ShiJian += 1;
}
// 自定义函数
void DF_ChuShiHua() {
mind_n_YiQiDongZiXianChengGeShu = 0;
mind_l_ZhiXingRenMing.clear();
display.setCursorLine(1);
display.printLine("正在初始化语音朗读模块......");
display.setCursorLine(1);
display.printLine("正在初始化HuskyLens......");
huskylens.beginI2CUntilSuccess();
huskylens.writeAlgorithm(ALGORITHM_FACE_RECOGNITION);
display.setCursorLine(1);
display.printLine("正在初始化网络......");
myIot.wifiConnect("Xiaomi_701", "1234567890");
while (!myIot.wifiStatus()) {yield();}
display.setCursorLine(1);
display.printLine("正在初始化MQTT......");
myIot.init("iot.dfrobot.com.cn","NUz32C_Mg","","NUkq2j_Ggz",topics,1883);
myIot.connect();
while (!myIot.connected()) {yield();}
display.setCursorLine(1);
display.printLine("已完成初始化");
delay(1000);
display.fillScreen(0);
}
void DF_HuoQuShiJian(String mind_s_MingZi) {
if ((mind_l_ZhiXingZiXianChengDaiMa[mind_l_ZhiXingRenMing.indexOf(mind_s_MingZi)-1]==1)) {
sstts.speak((String("你好") + String((String(mind_s_MingZi) + String((String("你的工作时间是:") + String(mind_n_ZiXianCheng1ShiJian)))))));
taskFree(loop1);
}
else if ((mind_l_ZhiXingZiXianChengDaiMa[mind_l_ZhiXingRenMing.indexOf(mind_s_MingZi)-1]==2)) {
sstts.speak((String("你好") + String((String(mind_s_MingZi) + String((String("你的工作时间是:") + String(mind_n_ZiXianCheng2ShiJian)))))));
taskFree(loop2);
}
else if ((mind_l_ZhiXingZiXianChengDaiMa[mind_l_ZhiXingRenMing.indexOf(mind_s_MingZi)-1]==3)) {
sstts.speak((String("你好") + String((String(mind_s_MingZi) + String((String("你的工作时间是:") + String(mind_n_ZiXianCheng3ShiJian)))))));
taskFree(loop3);
}
else if ((mind_l_ZhiXingZiXianChengDaiMa[mind_l_ZhiXingRenMing.indexOf(mind_s_MingZi)-1]==4)) {
sstts.speak((String("你好") + String((String(mind_s_MingZi) + String((String("你的工作时间是:") + String(mind_n_ZiXianCheng4ShiJian)))))));
taskFree(loop4);
}
else if ((mind_l_ZhiXingZiXianChengDaiMa[mind_l_ZhiXingRenMing.indexOf(mind_s_MingZi)-1]==5)) {
sstts.speak((String("你好") + String((String(mind_s_MingZi) + String((String("你的工作时间是:") + String(mind_n_ZiXianCheng5ShiJian)))))));
taskFree(loop5);
}
else if ((mind_l_ZhiXingZiXianChengDaiMa[mind_l_ZhiXingRenMing.indexOf(mind_s_MingZi)-1]==6)) {
sstts.speak((String("你好") + String((String(mind_s_MingZi) + String((String("你的工作时间是:") + String(mind_n_ZiXianCheng6ShiJian)))))));
taskFree(loop6);
}
else if ((mind_l_ZhiXingZiXianChengDaiMa[mind_l_ZhiXingRenMing.indexOf(mind_s_MingZi)-1]==7)) {
sstts.speak((String("你好") + String((String(mind_s_MingZi) + String((String("你的工作时间是:") + String(mind_n_ZiXianCheng7ShiJian)))))));
taskFree(loop7);
}
else {
sstts.speak((String("你好") + String((String(mind_s_MingZi) + String((String("你的工作时间是:") + String(mind_n_ZiXianCheng8ShiJian)))))));
taskFree(loop8);
}
}
// 事件回调函数
void onButtonAPressed() {
sstts.speak("请将脸靠近摄像头");
while (!huskylens.isAppearDirect(HUSKYLENSResultBlock)) {
huskylens.request();
yield();
}
huskylens.request();
if ((huskylens.readBlockCenterParameterDirect().ID>0)) {
mind_s_MingZi = mind_l_RenMing[huskylens.readBlockCenterParameterDirect().ID-1];
sstts.speak((String((String("欢迎") + String(mind_s_MingZi))) + String("来宁波市江北区实验小学做义工,让我们一起来劳动吧")));
display.setCursorLine(1);
display.printLine((String((String("欢迎") + String(mind_s_MingZi))) + String("来宁波市江北区实验小学做义工,让我们一起来劳动吧")));
delay(1000);
sstts.speak("现在开始计时");
display.setCursorLine(1);
display.printLine("现在开始计时");
mind_l_ZhiXingRenMing.push_back(mind_s_MingZi);
mind_l_ZhiXingZiXianChengDaiMa.push_back((String((mind_n_YiQiDongZiXianChengGeShu + 1))));
mind_n_YiQiDongZiXianChengGeShu += 1;
if ((mind_n_YiQiDongZiXianChengGeShu==1)) {
taskStart(loop1);
}
else if ((mind_n_YiQiDongZiXianChengGeShu==2)) {
taskStart(loop2);
}
else if ((mind_n_YiQiDongZiXianChengGeShu==3)) {
taskStart(loop3);
}
else if ((mind_n_YiQiDongZiXianChengGeShu==4)) {
taskStart(loop4);
}
else if ((mind_n_YiQiDongZiXianChengGeShu==5)) {
taskStart(loop5);
}
else if ((mind_n_YiQiDongZiXianChengGeShu==6)) {
taskStart(loop6);
}
else if ((mind_n_YiQiDongZiXianChengGeShu==7)) {
taskStart(loop7);
}
else {
taskStart(loop8);
}
}
}
void onButtonBPressed() {
sstts.speak("请将脸靠近摄像头");
while (!huskylens.isAppearDirect(HUSKYLENSResultBlock)) {
huskylens.request();
yield();
}
huskylens.request();
mind_s_MingZi = mind_l_RenMing[huskylens.readBlockCenterParameterDirect().ID-1];
if (mind_l_ZhiXingRenMing.contains(mind_s_MingZi)) {
DF_HuoQuShiJian(mind_s_MingZi);
}
else {
sstts.speak("你按错了");
}
}
------------------------------------------------------------
帮我看看哪里错了? |
|
|
|
|
|