串口屏在自动喂食系统领域应用的解决方案

该项目采用STONE升级型号:STWI101WT-01,10英寸1024×600分辨率工业级串口屏,可全屏显示该自动化食品配送系统的所有参数和设置。

全新升级的开发系统使用更加便捷,质量更加稳定可靠。特别是曲线功能的显示和控制更加简便。当然,新软件仍在持续优化和升级中, 更多便捷功能将逐步开发,敬请期待。

首先,我将介绍所使用的STONE串口屏。STWI101WT-01的技术参数如图(1)和图(2)所示。电源范围非常广泛,我们选择了符合要求的DC12V、1A直流稳压电源。

自动进料系统
图(a)STWI101WT-01技术参数
自动进料系统
图(2)STWI101WT-01电源要求

嵌入此串行屏幕的软件系统已升级,使命令更易于阅读和记忆,采用以下格式。

自动进料系统
图 (3) 新屏幕系统的命令格式

再次简要介绍自动喂食系统的概念。

该自动喂食演示系统基于以下功能概念(可假设为室内鸡舍)。

  • 可定制的喂食时间。
  • 可调节的喂食传送带速度。
  • 不投喂食物:设置在前几个位置并停止投喂。

此外,系统配备传感器开关板,可自动停在对应笼位前方。设有温度计监测室温,可设置通风定时器(例如每2小时通风15分钟)及粪便清理定时器等。当然,该演示系统仅用于介绍目的,实际应用中可根据客户需求添加各类功能。

本项目为参数设置和显示界面,其中第一级界面如图(4)所示,第二级和第三级界面内容类似。界面右上角显示当前日期和时间, 左上角的按钮可进入时间和日期的修正页面。

左侧还显示房间的实时温度,以及房间通风的设定频率(参数可调整为小时/每间隔,当达到设定值时,风扇会自动启动通风)。中间部分显示每日6次喂食的时间、喂食速度和喂食笼数量,每个值可通过滑动调整 (这是一个文本选择控件,可见数设置为1)。

下方是传送带的示意图,底部是检测无喂食的计数器,旁边是切换层数的按钮。通电后开始演示,设定喂食时间到达时,对应位置的灯泡会亮起,同时连接的传送带电机开始旋转驱动传送带移动, 有两种速度,根据设置值实现快慢速。当送料笼数量达到设定值时,将停止运动。

同时风扇将以固定间隔启动运行。演示板配备限位开关用于切换送料速度,该开关由伺服电机旋转触发。请观看演示视频以获取详细结果。

自动进料系统
图(4)第一级参数设置与显示界面

描述

  • 人机界面(HMI)与控制系统创建指南
  • 界面下载
  • 硬件材料及测试说明
  • 调试代码

1、HMI和控制创建说明

分钟选择器文本选择器每页有6个,例如我们希望精确到10分钟,可将选项设置为1:0;2:10;3:20;4:30;5:40;6:50;以便于调整。图(5)是分钟选择器属性的截图。在示例中,我们仅对 ts121 的 text_selector 控制属性进行了修改,其他部分的分钟 text_selector 控制仍使用选项:0-59。

该项目分为 3 层和 3 页, 每页包含6行4列的文本选择器控件,对齐方法可通过石设计师软件菜单栏中的多种对齐工具实现,详见图(6)。对齐前请先使用Shift键选中所有需对齐的控件,再点击对应的对齐图标。

自动进料系统
图 (5) min 文本选择器 ts121 的属性参数
自动进料系统
图 (6) 对齐图标

编程控件名称。

界面中的灯泡可在界面中6次投射后点亮,如图(7)所示为完全点亮状态。

第一层的6个灯泡均为IMAGE控件,自上而下依次命名为image11、image12、image13、image14、image15和image16。

相应地。

第二层的6个灯泡均为IMAGE控件,自上而下依次命名为image21、image22、image23、image24、image25和image26。

第三层的6个灯泡均为IMAGE控件,自上而下依次命名为image31、image32、image33、image34、image35 image36,从上到下依次命名。

自动进料系统
图 (7) 灯泡图像控件的命名

每层的六个供电参数(小时、分钟、速度和供电笼数量)在图 (8)中命名为。

第一层。

小时:ts111、ts112、ts113、ts114、ts115、ts116

分钟:ts121、 ts122, ts123, ts124, ts125, ts126

速度:ts131, ts132, ts133, ts134, ts135, ts136

喂食笼数量:ts141, ts142, ts143, ts144, ts145, ts146

第二级。

小时:ts211, ts212, ts213, ts214, ts215, ts216

分钟:ts221, ts222, ts223, ts224, ts225, ts226

速度:ts231、ts232、ts233、ts234、 ts235, ts236

喂料笼数量:ts241, ts242, ts243, ts244, ts245, ts246

第三级。

小时:ts311, ts312, ts313, ts314, ts315, ts316

分钟:ts321, ts322, ts323, ts324, ts325, ts326

速度:ts331, ts332, ts333, ts334, ts335, ts336

喂料笼数量:ts341, ts342, ts343, ts344, ts345, ts346

自动进料系统
图 (8) 节拍参数文本选择器控制命名

其他

每个室内通风页面都有一个文本选择器控制:ts151、ts251、ts351。

每页的数字时钟控制名称为:digit_clock1、digit_clock2、digit_clock3。

每页的感应无音高计数标签控制名称为 label11、label21 和 label31。

每页的温度标签控制名称为 label12、label22 和 label32。

2、接口下载

自动进料系统
图(9)STWI101WT-01串口屏幕背面视图

将计算机USB与STWI101WT-01串口屏幕的USB Type-A接口按图(9)所示连接。

通过点击石设计工具软件主菜单中的“调试”—“下载”,您可以

选择文件夹后会生成与项目同名的子文件夹(每次下载前需将最后生成的文件夹重命名,否则会返回错误)。

检查 STONE 串口屏幕背面的 DIP 开关,确保其处于“设备”位置。

使用 USB 通信电缆直接连接至计算机和显示屏的 USB 端口,电脑将弹出新磁盘文件夹。

将项目名称对应的子文件夹中的 /default/raw 文件夹复制到显示屏存储目录下的“default”文件夹!

首先,删除“default” 文件夹(仅保留图像文件夹),其他7个文件夹可删除。若图像文件夹被系统占用(如启动系统),写入时会提示错误,可检查确认。图像文件夹为标准标签图像,若需添加新标签和图像,可手动复制image/xx文件夹中的文件后合并(若无新图像导入, 可跳过同名图像文件夹内容)。

复制完成后,弹出新磁盘,拔掉USB连接线,按下STONE串口屏背面的RESET按钮。

3、硬件材料及指令测试

编程前需验证需使用的指令。我们使用串口助手检查 STONE 的反馈并验证命令的有效性。本项目涉及 5 种控制类型:按钮、标签、文本选择器、数字时钟和图像。

图 (10) 显示了本项目准备的材料。包括传送带、风扇、电机、速度控制板、感应套件、伺服电机、MCU 板等。在完成布线并与 STONE 串口屏幕通信后,我们编程实现人机交互。接线连接细节在此不做赘述。请参阅项目完成后录制的视频,以查看运动效果。

自动进料系统
 图 (10) 本项目演示材料

标签相关:

set_text 设置标签显示的文本

示例:

设置文本:(温度显示名称 = label22)

ST<{“cmd_code”: “set_text”, “type”: “label”, “widget”: “label22”, “text”: “23”}>ET Verify the upper screen OK

文本选择器相关:

0x1081 文本选择器值发送 (整数类型,主动发送: 在选择器调整后立即发布)

数据格式:

值: 数据段的最后四个字节

示例: (小时选择器控制名称 = ts111, 选项: 0-23, 当前 5, 当重新选择 7 时)

串口助手接收的十六进制数据为.

53 54 3C 10 81 00 09 74 73 31 31 31 31 00 00 00 07 3E 45 54 B4 ED OK

屏幕主动发送指令如下:

ST<0x10 0x81 0x00 0x09 ts111 0x00 0x00 0x00 0x00 0x07 >ET ts111 的当前值:0x07

与数字时钟相关:

set_date 设置数字时钟控制的日期和时间。

Get_date 获取 数字时钟控制的日期和时间。

示例:

设置日期和时间:

ST< {“cmd_code”: “set_date”, “type”: “digit_clock”, “widget”: “digit_clock”, “date”: “2022-05-27 21:30”}>ET Verify that the times of all three pages on the top screen are synchronized OK

ST< {“cmd_code”: “set_date”, “type”: “digit_clock”, “widget”: “digit_clock3”, “date”: “2022-05-28 22:30”}>ET The effect is the same, all 3 clocks are updated synchronously.

图 (11) 见软件说明书。

读取日期和时间:

自动进料系统
图 (11)

上述时间和日期读取命令已规划,但目前硬件和软件版本尚未支持,且以下命令的串口屏幕当前无反馈。因此演示程序通过程序自动启动显示功能。

Send: ST< {“cmd_code”: “get_date”, “type”: “digit_clock”, “widget”: “digit_clock1”}>ET

图像相关:

set_visible 设置控件的可见性。

示例:

设置灯泡点亮:

ST<{“cmd_code”: “set_visible”, “type”: “widget”, “widget”: “image11”, “visible”:true}>ET            First page first feeding bulb lit ok

4、调试代码

演示说明

本演示传送带的1档和2档速度通过伺服驱动器控制两组开关实现,室内通风则使用小型DC5V风扇演示。室内温度、送料笼数量可实际使用温度传感器和位置传感器, 此处直接写入命令。通电后,首先关闭所有灯显示(到预设时间后,再将对应位置的灯可见性设置为“TRUE”,表示工作状态)。随后写入实时时钟(RTC)时间。运行过程中读取屏幕上的RTC时间,并与设定喂食时间比较以决定是否开始喂食。第2级和第3级与第1级代码相同,因空间限制部分省略,不影响功能显示。

// Auto rice

// by Frank for STONE in 2022.05.28

/*
the word of CMD:
ST<{“cmd_code”: “get_date”, “type”: “digit_clock”, “widget”: “digit_clock1”}>ET
ST<0x10 0xF0 0x00 0x22 “digit_clock1” :2021-02-26 12:31:35 >ET
53 54 3C 10 F0 00 22 22 64 69 67 69 74 5F 63 6C 6F 63 6B 31 22 3A 32 30 32 31 2D 30 32 2D 32 36 20 31 32 3A 33 31 3A 33 35 3E 45 54 30 BB
ST<{“cmd_code”: “set_visible”, “type”: “widget”, “widget”: “image11”, “visible”:true}>ET
ST<{“cmd_code”: “set_date”, “type”: “digit_clock”, “widget”: “digit_clock1”, “date”: “2022-05-28 22:30”}>ET
st<0x10 0x81 0x00 0x09 ts111 0x00 0x00 0x00 0x00 0x07 >et
53 54 3C 10 81 00 09 74 73 31 31 31 31 00 00 00 07 3E 45 54 B4 ED
ST<{“cmd_code”: “set_text”, “type”: “label”, “widget”: “label22”, “text”: “23”}>ET

*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
int led = 13;
int fan = 6;
int iflag0 = 1;
int hourNow=3,minNow=55; // now RTC time!
int riceNum1=1,riceNum2=1,riceNum3=1;
int ts111=5,ts112=8,ts113=11,ts114=14,ts115=17,ts116=20; //hour of page 1
int ts121=10,ts122=10,ts123=10,ts124=10,ts125=10,ts126=10; //min of page 1
int ts131=1,ts132=1,ts133=1,ts134=1,ts135=1,ts136=1; //speed of page 1
int ts141=5,ts142=5,ts143=5,ts144=5,ts145=5,ts146=5; // rice num of page 1
int ts211=5,ts212=8,ts213=11,ts214=14,ts215=17,ts216=20; //hour of page 2
int ts221=10,ts222=10,ts223=10,ts224=10,ts225=10,ts226=10; //min of page 2
int ts231=1,ts232=1,ts233=1,ts234=1,ts235=1,ts236=1; //speed of page 2
int ts241=5,ts242=5,ts243=5,ts244=5,ts245=5,ts246=5; // rice num of page 2
int ts311=5,ts312=8,ts313=11,ts314=14,ts315=17,ts316=20; //hour of page 3
int ts321=10,ts322=10,ts323=10,ts324=10,ts325=10,ts326=10; //min of page 3
int ts331=1,ts332=1,ts333=1,ts334=1,ts335=1,ts336=1; //speed of page 3
int ts341=5,ts342=5,ts343=5,ts344=5,ts345=5,ts346=5; // rice num of page 3
//-------if(flag == 1) then start OUT ! ------------
int iflag11 = 0;
int iflag12 = 0;
int iflag13 = 0;
int iflag14 = 0;
int iflag15 = 0;
int iflag16 = 0;
int iflag21 = 0;
int iflag22 = 0;
int iflag23 = 0;
int iflag24 = 0;
int iflag25 = 0;
int iflag26 = 0;
int iflag31 = 0;
int iflag32 = 0;
int iflag33 = 0;
int iflag34 = 0;
int iflag35 = 0;
int iflag36 = 0;
void setup()
{
pinMode(led, OUTPUT); // initialize the digital pin as an output.
pinMode(fan, OUTPUT);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.write(pos); // tell servo to go to position in variable 'pos'
Serial.begin(115200); // Open the serial communication function and wait for the serial port to open
while (!Serial) {
Needed for Leonardo only
}
}
void loop()
{
int inChar;
// myservo.write(15); // all off
if(iflag0 == 1){ //only once!
iflag0 = 0;
//-------set date now------
Serial.println("ST<{\"cmd_code\":\"set_date\",\"type\":\"digit_clock\",\"widget\":\"digit_clock1\",\"date\":\"2022-05-28 03:52\" }>ET");
//-------set temp of page 1\2\3------
Serial.println("ST<{\"cmd_code\":\"set_text\",\"type\":\"label\",\"widget\":\"label12\",\"text\":\"23\"}>ET");
Serial.println("ST<{\"cmd_code\":\"set_text\",\"type\":\"label\",\"widget\":\"label22\",\"text\":\"23\"}>ET");
Serial.println("ST<{\"cmd_code\":\"set_text\",\"type\":\"label\",\"widget\":\"label32\",\"text\":\"23\"}>ET");
//-------set not rice of page 1\2\3------
Serial.println("ST<{\"cmd_code\":\"set_text\",\"type\":\"label\",\"widget\":\"label11\",\"text\":\"3\"}>ET");
Serial.println("ST<{\"cmd_code\":\"set_text\",\"type\":\"label\",\"widget\":\"label21\",\"text\":\"3\"}>ET");
Serial.println("ST<{\"cmd_code\":\"set_text\",\"type\":\"label\",\"widget\":\"label31\",\"text\":\"3\"}>ET");
//-------set all lamps off!------
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image11\",\"visible\":false}>ET");
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image12\",\"visible\":false}>ET");
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image13\",\"visible\":false}>ET");
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image14\",\"visible\":false}>ET");
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image15\",\"visible\":false}>ET");
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image16\",\"visible\":false}>ET");
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image21\",\"visible\":false}>ET");
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image22\",\"visible\":false}>ET");
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image23\",\"visible\":false}>ET");
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image24\",\"visible\":false}>ET");
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image25\",\"visible\":false}>ET");
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image26\",\"visible\":false}>ET");
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image31\",\"visible\":false}>ET");
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image32\",\"visible\":false}>ET");
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image33\",\"visible\":false}>ET");
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image34\",\"visible\":false}>ET");
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image35\",\"visible\":false}>ET");
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image36\",\"visible\":false}>ET");
delay (2000);
myservo.write(15); // speed = 0 off!
delay (2000);
delay (2000);
for(pos = 15; pos < 36; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
delay (2000);
delay (2000);
delay (2000);
delay (2000);
delay (2000);
delay (2000);
delay (2000);
myservo.write(15); // speed = 0 off!
delay (2000);
delay (2000);
for(pos = 15; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(55); // waits 15ms for the servo to reach the position
}
delay (2000);
delay (2000);
delay (2000);
delay (2000);
delay (2000);
delay (2000);
delay (2000);
myservo.write(15); // speed = 0 off!
delay (2000);
delay (2000);
delay (2000);
delay (2000);
digitalWrite(fan, HIGH);
delay (2000);
delay (2000);
delay (2000);
digitalWrite(fan, LOW);
delay (2000);
}//end if iflag0 = 1
//----- when 00:00 everyday -------
if(hourNow == 0 && minNow == 0) {
iflag11 = 0;
iflag12 = 0;
iflag13 = 0;
iflag14 = 0;
iflag15 = 0;
iflag16 = 0;
iflag21 = 0;
iflag22 = 0;
iflag23 = 0;
iflag24 = 0;
iflag25 = 0;
iflag26 = 0;
iflag31 = 0;
iflag32 = 0;
iflag33 = 0;
iflag34 = 0;
iflag35 = 0;
iflag36 = 0;
} //end if 00:00
//-------- fan work ---------
if(minNow == 0){digitalWrite(fan, HIGH);}
else{digitalWrite(fan, LOW);}
//------- rice time is ok1 -------------
if(hourNow == ts111 && minNow == ts121) {
iflag11 = 1;
riceNum1 = 0;
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image11\",\"visible\":true}>ET");
}
if(hourNow == ts112 && minNow == ts122) {
iflag12 = 1;
riceNum1 = 0;
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image12\",\"visible\":true}>ET");
}
if(hourNow == ts113 && minNow == ts123) {
iflag13 = 1;
riceNum1 = 0;
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image13\",\"visible\":true}>ET");
}
if(hourNow == ts114 && minNow == ts124) {
iflag14 = 1;
riceNum1 = 0;
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image14\",\"visible\":true}>ET");
}
if(hourNow == ts115 && minNow == ts125) {
iflag15 = 1;
riceNum1 = 0;
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image15\",\"visible\":true}>ET");
}
if(hourNow == ts116 && minNow == ts126) {
iflag16 = 1;
riceNum1 = 0;
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image16\",\"visible\":true}>ET");
}
//------- rice time is ok2 -------------
if(iflag11 == 1){
if(ts131 == 0){ //speed = 1
for(pos = 15; pos < 36; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
}else{ //speed = 2
for(pos = 15; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(55); // waits 15ms for the servo to reach the position
}
}//end else
if(riceNum1 >= ts141){
myservo.write(15); // speed = 0 off!
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image11\",\"visible\":false}>ET");
iflag11 = 0;
}//end if riceNum
}//end if iflag11
if(iflag12 == 1){
if(ts132 == 0){ //speed = 1
for(pos = 15; pos < 36; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
}else{ //speed = 2
for(pos = 15; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(55); // waits 15ms for the servo to reach the position
}
}//end else
if(riceNum1 >= ts142){
myservo.write(15); // speed = 0 off!
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image11\",\"visible\":false}>ET");
iflag12 = 0;
}//end if riceNum
}//end if iflag12
if(iflag13 == 1){
if(ts133 == 0){ //speed = 1
for(pos = 15; pos < 36; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
}else{ //speed = 2
for(pos = 15; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(55); // waits 15ms for the servo to reach the position
}
}//end else
if(riceNum1 >= ts143){
myservo.write(15); // speed = 0 off!
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image11\",\"visible\":false}>ET");
iflag13 = 0;
}//end if riceNum
}//end if iflag13
if(iflag14 == 1){
if(ts134 == 0){ //speed = 1
for(pos = 15; pos < 36; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
}else{ //speed = 2
for(pos = 15; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(55); // waits 15ms for the servo to reach the position
}
}//end else
if(riceNum1 >= ts144){
myservo.write(15); // speed = 0 off!
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image11\",\"visible\":false}>ET");
iflag14 = 0;
}//end if riceNum
}//end if iflag14
if(iflag15 == 1){
if(ts135 == 0){ //speed = 1
for(pos = 15; pos < 36; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
}else{ //speed = 2
for(pos = 15; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(55); // waits 15ms for the servo to reach the position
}
}//end else
if(riceNum1 >= ts145){
myservo.write(15); // speed = 0 off!
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image11\",\"visible\":false}>ET");
iflag15 = 0;
}//end if riceNum
}//end if iflag15
if(iflag16 == 1){
if(ts136 == 0){ //speed = 1
for(pos = 15; pos < 36; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
}else{ //speed = 2
for(pos = 15; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(55); // waits 15ms for the servo to reach the position
}
}//end else
if(riceNum1 >= ts146){
myservo.write(15); // speed = 0 off!
Serial.println("ST<{\"cmd_code\":\"set_visible\",\"type\":\"widget\",\"widget\":\"image11\",\"visible\":false}>ET");
iflag16 = 0;
}//end if riceNum
}//end if iflag16
// Read the information sent by the serial port:
if (Serial.available() > 0) { inChar = Serial.read(); }
//-------CMD jie ma begin-------
if (inChar == 0x74) // t
{
if (Serial.available() > 0){inChar = Serial.read();}
if (inChar == 0x73) // ts
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (inChar == 0x31) // ts1
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (inChar == 0x31) // ts11
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (inChar == 0x31) // ts111
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts111 = inChar;
}else if (inChar == 0x32) // ts112
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts112 = inChar;
}else if (inChar == 0x33) // 3
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts113 = inChar;
}else if (inChar == 0x34) // 4
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts114 = inChar;
}else if (inChar == 0x35) // 5
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts115 = inChar;
}else if (inChar == 0x36) // 6
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts116 = inChar;
}
}else if (inChar == 0x32) // ts12
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (inChar == 0x31) // ts121
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts121 = inChar;
}else if (inChar == 0x32) // ts122
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts122 = inChar;
}else if (inChar == 0x33) // ts123
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts123 = inChar;
}else if (inChar == 0x34) // 4
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts124 = inChar;
}else if (inChar == 0x35) // 5
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts125 = inChar;
}else if (inChar == 0x36) // 6
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts126 = inChar;
}
}else if (inChar == 0x33) // ts13
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (inChar == 0x31) // ts131
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts131 = inChar;
}else if (inChar == 0x32) // ts132
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts132 = inChar;
}else if (inChar == 0x33) // ts133
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts133 = inChar;
}else if (inChar == 0x34) // 4
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts134 = inChar;
}else if (inChar == 0x35) // 5
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts135 = inChar;
}else if (inChar == 0x36) // 6
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts136 = inChar;
}
}else if (inChar == 0x34) // ts14
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (inChar == 0x31) // ts141
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts141 = inChar;
}else if (inChar == 0x32) // ts142
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts142 = inChar;
}else if (inChar == 0x33) // ts143
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts143 = inChar;
}else if (inChar == 0x34) // 4
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts144 = inChar;
}else if (inChar == 0x35) // 5
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts145 = inChar;
}else if (inChar == 0x36) // 6
{
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
if (Serial.available() > 0){ inChar = Serial.read();}
ts146 = inChar;
}
}
}
}
}
//----- CMD jie ma end ---------
if (inChar==85) { //55H=85="U" speed = 1
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(fan, HIGH);
for(pos = 15; pos < 36; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(50); // waits 15ms for the servo to reach the position
}
} // end if.
if (inChar==87) { //57H=87="W" speed = 0
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(fan, HIGH);
myservo.write(15); // tell servo to go to position in variable 'pos'
} // end if.
if (inChar==86) { //56H=86="V" speed = 2
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(fan, LOW);
for(pos = 15; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(55); // waits 15ms for the servo to reach the position
}
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(200); // waits 1.6s
} // end if
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(3);
//digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(5);
}

滚动至顶部