在好例子网,分享、交流、成长!
您当前所在位置:首页C/C++ 开发实例嵌入式开发 → TFTLCD触摸屏实验--Button按钮控制LED

TFTLCD触摸屏实验--Button按钮控制LED

嵌入式开发

下载此实例
  • 开发语言:C/C++
  • 实例大小:0.26M
  • 下载次数:0
  • 浏览次数:22
  • 发布时间:2021-04-03
  • 实例类别:嵌入式开发
  • 发 布 人:JHCGHDCUK
  • 文件格式:.rar
  • 所需积分:2
 相关标签: button LED LCD TFT 触摸屏

实例介绍

【实例简介】TFTLCD触摸屏实验--Button按钮控制LED

【实例截图】51单片机例程

from clipboard

【核心代码】void Button_Test(void)
{
u8 i=0;
u8 LED1_PressFlag=0;
u8 LED2_PressFlag=0;
u8 LED3_PressFlag=0;

FRONT_COLOR=RED;
LCD_ShowString(10,10,tftlcd_data.width,tftlcd_data.height,16,"Button Test");

for(i=0;i<3;i )
{
Button_Create(BUTTON_START_X (BUTTON_SPACE_X BUTTON_WIDTH)*i,BUTTON_START_Y,BUTTON_WIDTH,BUTTON_HEIGHT,BUTTON_ARCSIZE,BUTTON_BACKCOLOR,BUTTON_FRONTCOLOR,16,Button_text[i]);
  gui_fill_circle(LED_START_X (LED_DIAMETER LED_SPACE_X)*i,LED_START_Y,LED_RADIUS,LED_BACKCOLOR);
}

while(1)
{
TOUCH_Scan();

if(xpt_xy.sta)
{
//LED1
if((xpt_xy.lcdx>=LED1_START_X) && (xpt_xy.lcdx<=LED1_END_X) && 
(xpt_xy.lcdy>=LED1_START_Y) && (xpt_xy.lcdy<=LED1_END_Y))
{
xpt_xy.lcdx=0;
xpt_xy.lcdy=0;
LED1_PressFlag=1;
}

//LED2
else if((xpt_xy.lcdx>=LED2_START_X) && (xpt_xy.lcdx<=LED2_END_X) && 
(xpt_xy.lcdy>=LED2_START_Y) && (xpt_xy.lcdy<=LED2_END_Y))
{
xpt_xy.lcdx=0;
xpt_xy.lcdy=0;
LED2_PressFlag=1;
}

//LED3
else if((xpt_xy.lcdx>=LED3_START_X) && (xpt_xy.lcdx<=LED3_END_X) && 
(xpt_xy.lcdy>=LED3_START_Y) && (xpt_xy.lcdy<=LED3_END_Y))
{
xpt_xy.lcdx=0;
xpt_xy.lcdy=0;
LED3_PressFlag=1;
}
}
else
{
if(LED1_PressFlag)
{
LED1_PressFlag=0;
Button_Create(BUTTON_START_X (BUTTON_SPACE_X BUTTON_WIDTH)*0,BUTTON_START_Y,BUTTON_WIDTH,BUTTON_HEIGHT,BUTTON_ARCSIZE,BUTTON_BACKCOLOR,BUTTON_FRONTCOLOR,16,Button_text[0]);
  LED1=1;
gui_fill_circle(LED_START_X (LED_DIAMETER LED_SPACE_X)*0,LED_START_Y,LED_RADIUS,LED_BACKCOLOR); 
}
else if(LED2_PressFlag)
{
LED2_PressFlag=0;
Button_Create(BUTTON_START_X (BUTTON_SPACE_X BUTTON_WIDTH)*1,BUTTON_START_Y,BUTTON_WIDTH,BUTTON_HEIGHT,BUTTON_ARCSIZE,BUTTON_BACKCOLOR,BUTTON_FRONTCOLOR,16,Button_text[1]);
  LED2=1;
gui_fill_circle(LED_START_X (LED_DIAMETER LED_SPACE_X)*1,LED_START_Y,LED_RADIUS,LED_BACKCOLOR); 
}
else if(LED3_PressFlag)
{
LED3_PressFlag=0;
Button_Create(BUTTON_START_X (BUTTON_SPACE_X BUTTON_WIDTH)*2,BUTTON_START_Y,BUTTON_WIDTH,BUTTON_HEIGHT,BUTTON_ARCSIZE,BUTTON_BACKCOLOR,BUTTON_FRONTCOLOR,16,Button_text[2]);
  LED3=1;
gui_fill_circle(LED_START_X (LED_DIAMETER LED_SPACE_X)*2,LED_START_Y,LED_RADIUS,LED_BACKCOLOR); 
}
}

if(LED1_PressFlag)
{
Button_PressCreate(BUTTON_START_X (BUTTON_SPACE_X BUTTON_WIDTH)*0,BUTTON_START_Y,BUTTON_WIDTH,BUTTON_HEIGHT,BUTTON_ARCSIZE,BUTTON_BACKCOLOR,BUTTON_FRONTCOLOR,16,Button_text[0]);
LED1=0;
gui_fill_circle(LED_START_X (LED_DIAMETER LED_SPACE_X)*0,LED_START_Y,LED_RADIUS,LED_FRONTCOLOR);
}
else if(LED2_PressFlag)
{
Button_PressCreate(BUTTON_START_X (BUTTON_SPACE_X BUTTON_WIDTH)*1,BUTTON_START_Y,BUTTON_WIDTH,BUTTON_HEIGHT,BUTTON_ARCSIZE,BUTTON_BACKCOLOR,BUTTON_FRONTCOLOR,16,Button_text[1]);
LED2=0;
gui_fill_circle(LED_START_X (LED_DIAMETER LED_SPACE_X)*1,LED_START_Y,LED_RADIUS,LED_FRONTCOLOR);
}
else if(LED3_PressFlag)
{
Button_PressCreate(BUTTON_START_X (BUTTON_SPACE_X BUTTON_WIDTH)*2,BUTTON_START_Y,BUTTON_WIDTH,BUTTON_HEIGHT,BUTTON_ARCSIZE,BUTTON_BACKCOLOR,BUTTON_FRONTCOLOR,16,Button_text[2]);
LED3=0;
gui_fill_circle(LED_START_X (LED_DIAMETER LED_SPACE_X)*2,LED_START_Y,LED_RADIUS,LED_FRONTCOLOR);
}
}
}

标签: button LED LCD TFT 触摸屏

实例下载地址

TFTLCD触摸屏实验--Button按钮控制LED

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
;
报警