• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
MKT-porter
博客园    首页    新随笔    联系   管理    订阅  订阅
串口屏开发曲线和文字
 
 
 
 
 

 

http://wiki.tjc1688.com/commands/add.html#add-1

 

 

 //往s0曲线控件的0通道添加数据30  最大255
2 add s0.id,0,30

  

 

add objid,ch,val

objid:曲线控件ID序号(此处必须是ID号,不支持使用控件名称),推荐使用s0.id这种形式

ch:曲线控件通道号(范围:0-3)

val:数据 (最小0,最大255,还取决于曲线控件的实际高度,例如曲线控件实际高200像素
,当你添加的值超过200的部分就显示不出来。超过255软件会自动取低8位,即对255取余)

 

 

 

 

 、

串口软件

 add 1,0,30\xff\xff\xff

 文字设置

首先设置一个字库

 

 

 

 

 然后添加  文本

 

 

烧录进去

 

 

单片机程序

 //#include <SoftwareSerial.h>
 //SoftwareSerial TJC(8,9);
 #define TJC Serial2

 int a;
 unsigned long nowtime;
 void setup() {
   // put your setup code here, to run once:
   //初始化串口
   Serial.begin(9600);
   TJC.begin(9600);

   //因为串口屏开机会发送88 ff ff ff,所以要清空串口缓冲区
   while (TJC.read() >= 0); //清空串口缓冲区
   TJC.print("page main\xff\xff\xff"); //发送命令让屏幕跳转到main页面
   nowtime = millis(); //获取当前已经运行的时间
 }


/*  \xff\xff\xff
randset 10,30 
n1.val=rand
n2.val=rand
n3.val=rand
n4.val=rand
add 1,0,n1.val
add 1,1,n2.val
add 1,2,n3.val


*/

// 温度 湿度 烟雾 CO
String node1[4]={"23","40","100","200"};
String node2[4]={"23","40","100","200"};
String node3[4]={"23","40","100","200"};


// 刷新控件
void SetValue(String id_,String msg){
     
     //用sprintf来格式化字符串,给n0的val属性赋值
     //sprintf(str, "n0.val=%d\xff\xff\xff", a);

      String show_msg=id_+".txt=\""+ msg+"\"\xff\xff\xff";
      char show_msg_c[show_msg.length()+1];
      show_msg.toCharArray(show_msg_c,show_msg.length()+ 1);
     
   
     //把字符串发送出去
      TJC.print(show_msg_c);
     // delay(1000);

     Serial.println(show_msg_c); 
  }

  
// 刷新控件
void DrawPIC(String id_,String chanel,String msg){
     
   
      //  add 1,0,n1.val
      String show_msg="add "+id_+","+ chanel +","+ msg+"\xff\xff\xff";
      char show_msg_c[show_msg.length()+1];
      show_msg.toCharArray(show_msg_c,show_msg.length()+ 1);
     
   
     //把字符串发送出去
      TJC.print(show_msg_c);
     // delay(1000);

     Serial.println(show_msg_c); 
  }

  
 void loop() {
  
   
   if (millis() >= nowtime + 1000) {
     nowtime = millis(); //获取当前已经运行的时间

     String msg=String(a);
     
     SetValue("t11",msg);
     SetValue("t12",msg);
     SetValue("t13",msg);
     SetValue("t14",msg);

     SetValue("t21",msg);
     SetValue("t22",msg);
     SetValue("t23",msg);
     SetValue("t24",msg);

     SetValue("t31",msg);
     SetValue("t32",msg);
     SetValue("t33",msg);
     SetValue("t34",msg);

     DrawPIC("1","0",msg);
     DrawPIC("1","1",msg);
     DrawPIC("1","2",msg);
     
     a++;
   }

 
 }

  

单独例程

#include "Api_SerialOled.h"

#define Serial1Zigbee Serial

unsigned long nowtime;

//分割结果
#define sleng 6 //数组大小 比实际多一个
String split_result[sleng];//手动动态调整数组大小,保证数组可以满足容量
 
/*字符串分割
输入参数
String zifuchuan,  输入字符串
String fengefu,    分隔符号-可以是多个
String result[]    输出结果
  
*/
void Split(String zifuchuan,String fengefu,String result[])
 {
  int weizhi; //找查的位置
  String temps;//临时字符串
  int i=0;
  do
  {
      weizhi = zifuchuan.indexOf(fengefu);//找到位置
      if(weizhi != -1)//如果位置不为空
      {
          temps=zifuchuan.substring(0,weizhi);//打印取第一个字符
          zifuchuan = zifuchuan.substring(weizhi+fengefu.length(), zifuchuan.length());
          //分隔后只取后面一段内容 以方便后面找查
      }
      else
      {  //上面实在找不到了就把最后的 一个分割值赋值出来以免遗漏
         if(zifuchuan.length() > 0)
          temps=zifuchuan;
      }
  
      result[i++]=temps;
      //Serial.println(result[i-1]);//在这里执行分割出来的字符下面不然又清空了
      temps="";
   }
   while(weizhi >=0);
  }


bool flag_do=0;
/* 
sensor1-12-23-65-65-;
sensor2-112-213-615-65-;
sensor3-02-31-23-44-;
*/
String GetData(String sensor,String action){
  
     //if(flag_do==0){flag_do=1;}
     //else{return "wait";}
     
     //String ShowMsg =String()+ "sensor1"+"-"+"getdata"+";";
     String ShowMsg =String()+ sensor +"-"+action+"-;";
     while(Serial1Zigbee.read() >= 0){}//清空缓存
     //转发给单片机处理
     Serial1Zigbee.println(ShowMsg);  

     delay(1000);
     //等待单片机回应消息
     String REC_comdata;
     if (Serial1Zigbee.available()){ 
         REC_comdata =Serial1Zigbee.readStringUntil(';');
         //REC_comdata=REC_comdata.replace("\n","");
         Serial.print("Rec_arduino:");Serial.println(REC_comdata);
           
         //2 ========解析命令 
         String split_input=REC_comdata;
          //2-0解析数据 sensor-on
          Split(split_input,"-",split_result);//分割调用
          //2-1打印消息 0-sensor  1-on
          for(int i=0;i<sleng;i++)
          {
            if(split_result[i]!="")
            {
             //Serial.println(String(i)+"-"+split_result[i]);
            }
            
         }

         String sensor_name=split_result[0];//
         String vlaue_wendu=split_result[1];//
         String vlaue_shidu=split_result[2];//
         String vlaue_mq2=split_result[3];//
         String vlaue_mq9=split_result[4];//

          if(sensor_name=="sensor1" ){
            Serial.println("sensor1");
           node1[0]= vlaue_wendu;
           node1[1]= vlaue_shidu;
           node1[2]= vlaue_mq2;
           node1[3]= vlaue_mq9;
          }
          else if(sensor_name=="sensor2"){
            Serial.println("sensor2");
           node2[0]= vlaue_wendu;
           node2[1]= vlaue_shidu;
           node2[2]= vlaue_mq2;
           node2[3]= vlaue_mq9;
          }
          else if(sensor_name=="sensor3"){
            Serial.println("sensor3");
           node3[0]= vlaue_wendu;
           node3[1]= vlaue_shidu;
           node3[2]= vlaue_mq2;
           node3[3]= vlaue_mq9;
          }


                  
         REC_comdata="ok";  
         //flag_do=0;
         return REC_comdata;
     }
     else{
           
          REC_comdata="no";
          // flag_do=0;
          //Serial.print("Rec_arduino:");Serial.println(REC_comdata);
          return REC_comdata;
      }
     
  }


 void setup() {
   // put your setup code here, to run once:
   //初始化串口
   Serial.begin(9600);
   Serial1Zigbee.begin(9600);
   TJC.begin(9600);

   //因为串口屏开机会发送88 ff ff ff,所以要清空串口缓冲区
   while (TJC.read() >= 0); //清空串口缓冲区
   TJC.print("page main\xff\xff\xff"); //发送命令让屏幕跳转到main页面
   nowtime = millis(); //获取当前已经运行的时间
 }
  
 void loop() {
  
     
   if (millis() >= nowtime + 2000) {
     nowtime = millis(); //获取当前已经运行的时间

     String REC_comdata =GetData("sensor1","getdata");
     if (REC_comdata=="ok"){  OELD_showonce_sensor();}
     REC_comdata =GetData("sensor2","getdata");
     if (REC_comdata=="ok"){  OELD_showonce_sensor();}
     REC_comdata =GetData("sensor3","getdata");
     if (REC_comdata=="ok"){  OELD_showonce_sensor();}
   }
 }

  Api_SerialOled.h

 
 
//#include <SoftwareSerial.h>
//SoftwareSerial TJC(8,9);

 
#define TJC Serial2
int a;

 

/*  \xff\xff\xff
randset 10,30 
n1.val=rand
n2.val=rand
n3.val=rand
n4.val=rand
add 1,0,n1.val
add 1,1,n2.val
add 1,2,n3.val


*/

// 温度 湿度 烟雾 CO
String node1[4]={"23","40","100","200"};
String node2[4]={"23","40","100","200"};
String node3[4]={"23","40","100","200"};


// 刷新控件
void SetValue(String id_,String msg){
     
     //用sprintf来格式化字符串,给n0的val属性赋值
     //sprintf(str, "n0.val=%d\xff\xff\xff", a);

      String show_msg=id_+".txt=\""+ msg+"\"\xff\xff\xff";
      char show_msg_c[show_msg.length()+1];
      show_msg.toCharArray(show_msg_c,show_msg.length()+ 1);
     
   
     //把字符串发送出去
      TJC.print(show_msg_c);
     // delay(1000);

     Serial.println(show_msg_c); 
  }

  
// 刷新控件
void DrawPIC(String id_,String chanel,String msg){
     
   
      //  add 1,0,n1.val
      String show_msg="add "+id_+","+ chanel +","+ msg+"\xff\xff\xff";
      char show_msg_c[show_msg.length()+1];
      show_msg.toCharArray(show_msg_c,show_msg.length()+ 1);
     
   
     //把字符串发送出去
      TJC.print(show_msg_c);
     // delay(1000);

     //Serial.println(show_msg_c); 
  }



void OELD_showonce(String msg ){
  
  


     
     SetValue("t11",msg);
     SetValue("t12",msg);
     SetValue("t13",msg);
     SetValue("t14",msg);

     SetValue("t21",msg);
     SetValue("t22",msg);
     SetValue("t23",msg);
     SetValue("t24",msg);

     SetValue("t31",msg);
     SetValue("t32",msg);
     SetValue("t33",msg);
     SetValue("t34",msg);

     DrawPIC("1","0",msg);
     DrawPIC("1","1",msg);
     DrawPIC("1","2",msg);
     
    
  }
  
void OELD_showonce_sensor( ){
  
     SetValue("t11",node1[0]);
     SetValue("t12",node1[1]);
     SetValue("t13",node1[2]);
     SetValue("t14",node1[3]);

     SetValue("t21",node2[0]);
     SetValue("t22",node2[1]);
     SetValue("t23",node2[2]);
     SetValue("t24",node2[3]);

     SetValue("t31",node3[0]);
     SetValue("t32",node3[1]);
     SetValue("t33",node3[2]);
     SetValue("t34",node3[3]);

     DrawPIC("1","0",node1[0]);
     DrawPIC("1","1",node2[0]);
     DrawPIC("1","2",node3[0]);
     
  }

  

  

posted on 2024-05-10 03:54  MKT-porter  阅读(161)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3