Touch Screen for Automated Feeding System

This project adopts STONE upgraded model: STWI101WT-01, 10″ 1024*600 resolution industrial serial touch screen, which can display all parameters and settings of this automated food delivery system in full screen.

The new upgraded development system is more convenient to use, and the quality is more stable and reliable. Especially the curve function is easier to display and control. Of course, the new software is still being improved and upgraded, more and more convenient functions will be developed gradually, we will see.

First of all, I would like to introduce the STONE screen I am using. the technical parameters of STWI101WT-01 are shown in Figures (1) and Figure (2). The power supply range is very wide, we choose the DC12V current 1A DC regulated power supply that can meet the requirements.

自动进料系统
Figure (a) STWI101WT-01 technical parameters
自动进料系统
Figure (2) Power Requirements for the STWI101WT-01

The software system embedded in this serial screen has been upgraded to make the commands easy to read and remember, in the following format.

自动进料系统
Figure (3) Command format of the new screen system

Again, a little more on the idea of an automated feeding system.

This automated feeding demonstration system is based on the following functional concept (which can be assumed to be an indoor chicken farm).

  • Customizable feeding times.
  • Adjustable speed of the feeding conveyor belt.
  • Do not cast food: set on the first few and don’t cast food.

In addition, there is a sensor switch plate that automatically stays in front of the corresponding cage position. There is a thermometer to monitor the room temperature, and you can set a timer for ventilation (e.g. 15 minutes every 2 hours), and a timer for manure cleaning, etc. Of course, this demonstration system is only for the purpose of introducing, in actual use, we can add various functions as required by customers.

This project is a parameter setting and display interface for each of the three levels, where the first level interface is shown in Figure (4), and the second and third level interfaces are similar in content. The interface will display the current date and time on the upper right, and the button on the upper left will access the correction page of time and date.

The left side also shows the real time temperature of the room, and the set frequency of ventilation of the room (the parameter is adjustable in hours/per interval, and the fan is automatically activated to ventilate the room when the point is reached). The middle part shows the time of the 6 daily feeds, the feed rate, and the number of feed cages, each value can be adjusted by sliding (it’s a text_selector control with visible_num set to 1).

Below is a schematic of the conveyor belt, the bottom is the count for sensing no feeding, next to it is the button to switch the layers. Power on to start the demonstration, the set feeding time is up, the light bulb will light up at that position, and at the same time the connected conveyor belt motor will rotate to drive the conveyor belt movement, there are two speeds, will achieve fast and slow speed according to the set value. When the number of feeding cage is reached, it will stop the movement.

Also the fan will start running at regular intervals. The demo board has a limit switch for switching the feeding speed, which is actuated by the rotation of the servo. Please watch the demo video for detailed results.

自动进料系统
Figure (4) First level parameter setting and display interface

Description

  • HMI and control creation instructions
  • Interface Download
  • Hardware materials and instruction testing
  • debugging code

1、HMI and control creation instructions

The minute selector text_selector has 6 per page, such as we want to be accurate only to 10min, OPTIONS can be set to 1:0;2:10;3:20;4:30;5:40;6:50; so that it is easy to adjust. Figure (5) is a screenshot of the properties of the min selector. In the sample, we have only made changes to the text_selector control property of ts121, for other parts of the min’s text_selector control we still use options:0-59.

This project is 3 layers and 3 pages, each page is 6 rows and 4 columns of text_selector controls, the alignment method can be used stone designer software menu bar on a variety of forms of alignment tools, see Figure (6). Use the shift key to select all controls that need to be aligned before alignment, and then click the corresponding alignment icon.

自动进料系统
Figure (5) Property parameters of the min text selector ts121
自动进料系统
Figure (6) Alignment Icon

Programming control name.

The bulb in front of the interface can be lit by the time of 6 casts in the interface, as shown in figure (7) for a fully lit situation.

The first layer of 6 bulbs is all IMAGE controls, named image11, image12, image13, image14, image15, and image16 from the top down.

Accordingly.

The second layer of 6 bulbs is all IMAGE controls, named image21, image22, image23, image24, image25, and image26 from the top down.

The third layer of 6 bulbs is all IMAGE controls, named image31, image32, image33, image34, image35, and image36 from the top down.

自动进料系统
Figure (7) Naming of the light bulb image control

The six feeding parameters (hours, minutes, speed, and number of feeding cages) for each layer were named in Figure (8).

Level 1.

Hours: ts111, ts112, ts113, ts114, ts115, ts116

Minutes: ts121, ts122, ts123, ts124, ts125, ts126

Speed: ts131, ts132, ts133, ts134, ts135, ts136

Number of feeding cages: ts141, ts142, ts143, ts144, ts145, ts146

Tier 2.

Hours: ts211, ts212, ts213, ts214, ts215, ts216

Minutes: ts221, ts222, ts223, ts224, ts225, ts226

Speed: ts231, ts232, ts233, ts234, ts235, ts236

Number of feeding cages: ts241, ts242, ts243, ts244, ts245, ts246

Tier 3.

Hours: ts311, ts312, ts313, ts314, ts315, ts316

Minutes: ts321, ts322, ts323, ts324, ts325, ts326

Speed: ts331, ts332, ts333, ts334, ts335, ts336

Number of feeding cages: ts341, ts342, ts343, ts344, ts345, ts346

自动进料系统
Figure (8) Pitching parameter text_selector control naming

Other.

There is a text_selector control for each page of indoor ventilation: ts151, ts251, ts351.

The digit clock control names on each page are: digit_clock1, digit_clock2, digit_clock3.

The inductive no-pitch count label control names for each page are label11, label21, and label31.

The temperature label control names for each page are label12, label22, and label32.

2、Interface Download

自动进料系统
Figure (9) Back view of STWI101WT-01 serial screen

Connect the computer USB and the USB Type-A port of the STWI101WT-01 serial screen as shown in Figure (9).

By clicking on debugging — “download” under the main menu of the stone designer tool software, you can

Selecting the folder will generate a subfolder with the same name as the project (the last generated folder should be renamed before each download. Otherwise it returns an error).

Check the dip switch on the back of the STONE serial screen to the “device” position above.

Use the USB communication cable to connect directly to the computer and the display USB port, the PC will pop up the new disk folder.

Copy the /default/raw folder from the subfolder of the same name as the project you just created to the “default” folder in the display storage directory!

First, delete the “default” folder except for the image folder of the other 7 folders, the image folder may be in the case of the boot system in occupation, writing will prompt an error, a check can be seen, the image folder is the standard label images, if there are new labels and images to add, you can compare image/xx folder file after manual copy to join (if there is no new image import, image folder content of the same name can be skipped).

When Copy is complete eject the new disk, unplug the USB connection cable, and press the RESET button on the back of the STONE serial screen.

3、Hardware materials and instruction testing

Verify the commands that need to be used before programming. We use the serial assistant to check the feedback from STONE and verify the validity of the commands. This project involves 5 types of controls: button, label, text_selector, digit clock, and image.

Figure (10) shows the materials prepared for this project. There are conveyor belt, fan, motor, speed control board, induction kit, servo, MCU board,s etc. We program the human-machine interaction after wiring them and communicating with the STONE serial screen. The wiring connections will not be detailed. Please see the video recorded after completion showing the motion effect.

自动进料系统
Figure (10) Demonstration materials for this project

Label Related:

set_text  Set the text displayed by the label

Example:

Set text: (temperature display name = label22)

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

text selector related:

0x1081  text selector value is sent  (int type Active posting: posted as soon as the selector is adjusted)

Data format:

value value: the last four bytes of the data section

Example: (hour selector control name = ts111, options: 0-23, current 5, when 7 is reselected)

The hexadecimal data received by the serial assistant is.

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

The screen actively gives instructions viz.

ST<0x10 0x81 0x00 0x09 ts111 0x00 0x00 0x00 0x00 0x07 >ET   Current value of ts111: 0x07

Digit clock related:

set_date  Sets the date and time of the digit_clock control.

Get_date  Retrieve the date and time of the digit_clock control.

Example:

Set the date and time:

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.

Figure (11) is given in the software instruction set.

Read the date and time:

自动进料系统
Figure (11)

The above time and date reading commands have been planned, but are still not supported by the current hardware and software versions at hand, and the following commands serial screen currently has no feedback. Therefore the demo starts the display function automatically by the program.

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

Image related:

set_visible  Sets the visibility of the control.

Example:

Set the bulb to light up:

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

4、Debug code

Presentation notes

The 1st and 2nd gear speed of this demo conveyor belt is achieved by changing two sets of switches through the servo drive, and the indoor ventilation is demonstrated using a small DC5V fan. Indoor temperature, feeding cage count can actually use temperature sensor and position sensor, this place direct command write instead. When the power is turned on, first turn off all the bulbs display (when the time comes, then let the corresponding position of the bulb visibility set “TRUE”, indicating the working status.) Then, the RTC time is written. The RTC time of the screen is read during operation and compared with the set feeding time to decide whether to start feeding. Levels 2 and 3 are the same as the code in level 1, and are partially omitted for space reasons, not affecting the functional display.

 

// 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);
}

Scroll to Top