赞
踩
背景界面的编写,可以方便到时候从某个功能退出时,直接把屏幕恢复到主界面
- void back_screen(void) //显示界面函数
- {
-
- Lcd_ColorBox(0,0,320,240,WHITE); //清屏,显示为白色
- print_text(30,70,'c',RED,YELLOW); //在某某坐标显示一个char类型字符
- print_text(30,78,'a',RED,YELLOW); //camera即摄像头按钮
- print_text(30,86,'m',RED,YELLOW);
- print_text(30,94,'e',RED,YELLOW);
- print_text(30,102,'r',RED,YELLOW);
- print_text(30,110,'a',RED,YELLOW);
-
- print_text(30,10,'R',RED,YELLOW); //rece 即receive 蓝牙接收数据显示
- print_text(30,18,'e',RED,YELLOW);
- print_text(30,26,'c',RED,YELLOW);
- print_text(30,34,'e',RED,YELLOW);
- wite(30,50,0,RED,YELLOW); //这个是在屏幕上显示个冒号
-
- print_text(30,160,'G',RED,YELLOW); //gogo发车按钮,可以根据自己的实际用途更改
- print_text(30,168,'O',RED,YELLOW);
- print_text(30,176,'G',RED,YELLOW);
- print_text(30,184,'O',RED,YELLOW);
-
- //操作值P的滑杆显示
- print_text(312,5,'P',BLUE,WHITE); //在屏幕上显示p
- Lcd_ColorBox(304,13,2,203,MAROON); //画一根棕色的线
- wite(312,p+13,0,YELLOW,YELLOW); //在线上根据p的值的大小显示滑块的位置
- print_number(312,216,p,BLACK,WHITE,3);
-
- print_text(250,5,'D',BLUE,WHITE); //操作值D的滑杆显示
- Lcd_ColorBox(242,13,2,203,MAROON);
- wite(250,d+13,0,YELLOW,YELLOW);
- print_number(250,216,d,BLACK,WHITE,3);
-
- print_text(188,5,'S',BLUE,WHITE); // 操作值S的滑杆显示 即舵机角度
- Lcd_ColorBox(180,13,2,203,MAROON);
- wite(188,servo+13,0,YELLOW,YELLOW);
- print_number(188,216,servo,BLACK,WHITE,3);
-
- print_text(126,5,'A',BLUE,WHITE); //电机A的速度滑杆显示
- Lcd_ColorBox(120,13,2,203,MAROON);
- wite(128,motor1+113,0,YELLOW,YELLOW); //判断速方向,进而显示±
- if(motor1>=0)
- {
- print_number(128,216,motor1,BLACK,WHITE,3);
- wite(114,216,11,BLACK,WHITE);
- }
- else
- {
- print_number(128,216,(-motor1),BLACK,WHITE,3);
- wite(114,216,13,BLACK,WHITE);
- }
-
-
- print_text(64,5,'B',BLUE,WHITE);
- Lcd_ColorBox(58,13,2,203,MAROON);
- wite(66,motor2+113,0,YELLOW,YELLOW);
- if(motor2>=0)
- {
- print_number(66,216,motor2,BLACK,WHITE,3);
- wite(52,216,11,BLACK,WHITE);
- }
- else
- {
- print_number(66,216,(-motor2),BLACK,WHITE,3);
- wite(52,216,13,BLACK,WHITE);
- }
-
- }
轮询我是在main里面的while循环轮询,有某些触摸产生时,判断触摸的位置,进入相应的程序
- while(1)
-
- {
- flag=0; //屏幕触摸中断标志位,一般屏幕中断不开启因为采用轮询,在进入摄像头的程序后,怕再次轮询耽误摄像头执行效率就用了触摸中断返回
- tx=TOUCH_X(); //读取触摸的x轴坐标
- ty=TOUCH_Y();//读取触摸的y轴坐标 我的屏幕上横向的是y轴
- print_text(270,142,'x',BLACK,WHITE); //显示出读到的坐标,方便开发GUI时快速找准触摸位置
- print_number(270,158,tx,BLACK,WHITE,4);
- print_text(270,190,'y',BLACK,WHITE);
- print_number(270,206,ty,BLACK,WHITE,4);
- if(tx>20&&tx<65) //p 判断如果触摸点是在P对应的滑杆上则执行以下程序
- {
- if(ty<21)ty=21; //限幅,
- if(p>200)p=200;
- p=ty-21; //将触摸的位置坐标赋给p值,-21是为了补偿
-
- Lcd_ColorBox(296,13,17,203,WHITE); //首先清空p滑杆
- Lcd_ColorBox(304,13,2,203,MAROON); //画上滑杆
- wite(312,p+13,0,YELLOW,YELLOW); //显示出滑杆对应的位置
- print_number(312,216,p,BLACK,WHITE,3); //并在滑杆尽头显示p的数值
- }
-
- if(tx>73&&tx<128) //D
- {
- if(ty<21)ty=21;
- d=ty-21;
- if(d>200)d=200;
- Lcd_ColorBox(234,13,17,203,WHITE);
- Lcd_ColorBox(242,13,2,203,MAROON);
- wite(250,d+13,0,YELLOW,YELLOW);
- print_number(250,216,d,BLACK,WHITE,3);
- }
-
- if(tx>288&&tx<320&&ty>73&&ty<120) //摄像头入口程序
- {
-
-
- cam_backround();
- VS_Enable();
- delay_ms(1000);
- touch_Enable();
- while(flag==0);
- PLCK_Disable();
- touch_Disable();
-
- back_screen(); //摄像头结束后返回主界面
-
- }
- if(tx>135&&tx<186) //舵机入口程序
- {
- if(ty<42)ty=42;
- servo=ty-21;
- if(servo>170)servo=170;
- Lcd_ColorBox(172,13,17,203,WHITE);
- Lcd_ColorBox(180,13,2,203,MAROON);
- wite(188,servo+13,0,YELLOW,YELLOW);
- print_number(188,216,servo,BLACK,WHITE,3);
- TIM_SetCompare1(TIM1,(9*servo+1750));
- }
-
- if(tx<240&&tx>190) //motor1程序,可按需求编写
- {
- motor_off(2);
- motor_off(1);
- if(ty<21)ty=21;
- motor1=ty-21-100;
- if(motor1>100)motor1=100;
- Lcd_ColorBox(112,13,17,203,WHITE);
- Lcd_ColorBox(120,13,2,203,MAROON);
- wite(128,motor1+113,0,YELLOW,YELLOW);
- if(motor1>=0)
- {
- print_number(128,216,motor1,BLACK,WHITE,3);
- wite(114,216,11,BLACK,WHITE);
- }
- else
- {
- print_number(128,216,(-motor1),BLACK,WHITE,3);
- wite(114,216,13,BLACK,WHITE);
- }
-
- }
-
- }
效果演示(gif自动加速,无奈)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。