代码首先要修改按钮的初始化
/**
*
@brief Touch_Button_Init 初始化按钮参数
* @param 无
* @retval 无
*/
void Touch_Button_Init(void)
{
/*第一列,主要为颜色按钮*/
button[0].start_x = BUTTON_START_X;
button[0].start_y = 0;
button[0].end_x = BUTTON_START_X+COLOR_BLOCK_WIDTH ;
button[0].end_y = COLOR_BLOCK_HEIGHT;
button[0].para = 1;
button[0].touch_flag = 0;
button[0].draw_btn = Draw_Num_Button ;
button[0].btn_command = Command_Select_Meannum ;
button[1].start_x = BUTTON_START_X;
button[1].start_y = COLOR_BLOCK_HEIGHT;
button[1].end_x = BUTTON_START_X+COLOR_BLOCK_WIDTH ;
button[1].end_y = COLOR_BLOCK_HEIGHT*2;
button[1].para = 2;
button[1].touch_flag = 0;
button[1].draw_btn = Draw_Num_Button ;
button[1].btn_command = Command_Select_Light ;
button[2].start_x = BUTTON_START_X;
button[2].start_y = COLOR_BLOCK_HEIGHT*2;
button[2].end_x = BUTTON_START_X+COLOR_BLOCK_WIDTH ;
button[2].end_y = COLOR_BLOCK_HEIGHT*3;
button[2].para = 3;
button[2].touch_flag = 0;
button[2].draw_btn = Draw_Num_Button ;
button[2].btn_command = Command_Select_Color ;
button[3].start_x = BUTTON_START_X;
button[3].start_y = COLOR_BLOCK_HEIGHT*3;
button[3].end_x = BUTTON_START_X+COLOR_BLOCK_WIDTH ;
button[3].end_y = COLOR_BLOCK_HEIGHT*4;
button[3].para = 4;
button[3].touch_flag = 0;
button[3].draw_btn = Draw_Num_Button ;
button[3].btn_command = Command_Select_Color ;
button[4].start_x = BUTTON_START_X;
button[4].start_y = COLOR_BLOCK_HEIGHT*4;
button[4].end_x = BUTTON_START_X+COLOR_BLOCK_WIDTH ;
button[4].end_y = COLOR_BLOCK_HEIGHT*5;
button[4].para = 5;
button[4].touch_flag = 0;
button[4].draw_btn = Draw_Num_Button ;
button[4].btn_command = Command_Select_Color ;
button[5].start_x = BUTTON_START_X;
button[5].start_y = COLOR_BLOCK_HEIGHT*5;
button[5].end_x = BUTTON_START_X+COLOR_BLOCK_WIDTH ;
button[5].end_y = COLOR_BLOCK_HEIGHT*6;
button[5].para = 6;
button[5].touch_flag = 0;
button[5].draw_btn = Draw_Num_Button ;
button[5].btn_command = Command_Select_Color ;
button[6].start_x = BUTTON_START_X;
button[6].start_y = COLOR_BLOCK_HEIGHT*6;
button[6].end_x = BUTTON_START_X+COLOR_BLOCK_WIDTH ;
button[6].end_y = COLOR_BLOCK_HEIGHT*7;
button[6].para = 7;
button[6].touch_flag = 0;
button[6].draw_btn = Draw_Num_Button ;
button[6].btn_command = Command_Select_Color ;
button[7].start_x = BUTTON_START_X;
button[7].start_y = COLOR_BLOCK_HEIGHT*7;
button[7].end_x = BUTTON_START_X+COLOR_BLOCK_WIDTH ;
button[7].end_y = LCD_Y_LENGTH;
button[7].para = CL_BUTTON_GREY;
button[7].touch_flag = 0;
button[7].draw_btn = Draw_Clear_Button ;
button[7].btn_command = Command_Clear_Palette ;
/*第二列,主要为画刷按钮*/
button[8].start_x = BUTTON_START_X + COLOR_BLOCK_WIDTH;
button[8].start_y = 0;
button[8].end_x = BUTTON_START_X + COLOR_BLOCK_WIDTH*2 ;
button[8].end_y = COLOR_BLOCK_HEIGHT;
button[8].para = 9;
button[8].touch_flag = 0;
button[8].draw_btn = Draw_Num_Button ;
button[8].btn_command = Command_Select_Meannum ;
button[9].start_x = BUTTON_START_X + COLOR_BLOCK_WIDTH;
button[9].start_y = COLOR_BLOCK_HEIGHT;
button[9].end_x = BUTTON_START_X + COLOR_BLOCK_WIDTH*2 ;
button[9].end_y = COLOR_BLOCK_HEIGHT*2;
button[9].para = 10;
button[9].touch_flag = 0;
button[9].draw_btn = Draw_Num_Button ;
button[9].btn_command = Command_Select_Light ;
button[10].start_x =BUTTON_START_X + COLOR_BLOCK_WIDTH;
button[10].start_y = COLOR_BLOCK_HEIGHT*2;
button[10].end_x = BUTTON_START_X + COLOR_BLOCK_WIDTH*2 ;
button[10].end_y = COLOR_BLOCK_HEIGHT*3;
button[10].para = 11;
button[10].touch_flag = 0;
button[10].draw_btn = Draw_Shape_Button ;
button[10].btn_command = Command_Select_Brush ;
button[11].start_x = BUTTON_START_X + COLOR_BLOCK_WIDTH;
button[11].start_y = COLOR_BLOCK_HEIGHT*3;
button[11].end_x = BUTTON_START_X + COLOR_BLOCK_WIDTH*2 ;
button[11].end_y = COLOR_BLOCK_HEIGHT*4;
button[11].para = 12;
button[11].touch_flag = 0;
button[11].draw_btn = Draw_Shape_Button ;
button[11].btn_command = Command_Select_Brush ;
button[12].start_x = BUTTON_START_X + COLOR_BLOCK_WIDTH;
button[12].start_y = COLOR_BLOCK_HEIGHT*4;
button[12].end_x = BUTTON_START_X + COLOR_BLOCK_WIDTH*2 ;
button[12].end_y = COLOR_BLOCK_HEIGHT*5;
button[12].para = 13;
button[12].touch_flag = 0;
button[12].draw_btn = Draw_Shape_Button ;
button[12].btn_command = Command_Select_Brush ;
button[13].start_x = BUTTON_START_X + COLOR_BLOCK_WIDTH;
button[13].start_y = COLOR_BLOCK_HEIGHT*5;
button[13].end_x = BUTTON_START_X + COLOR_BLOCK_WIDTH*2 ;
button[13].end_y = COLOR_BLOCK_HEIGHT*6;
button[13].para = 14;
button[13].touch_flag = 0;
button[13].draw_btn = Draw_Shape_Button ;
button[13].btn_command = Command_Select_Brush ;
button[14].start_x = BUTTON_START_X + COLOR_BLOCK_WIDTH;
button[14].start_y = COLOR_BLOCK_HEIGHT*6;
button[14].end_x = BUTTON_START_X + COLOR_BLOCK_WIDTH*2 ;
button[14].end_y = COLOR_BLOCK_HEIGHT*7;
button[14].para = 15;
button[14].touch_flag = 0;
button[14].draw_btn = Draw_Shape_Button ;
button[14].btn_command = Command_Select_Brush ;
button[15].start_x = BUTTON_START_X + COLOR_BLOCK_WIDTH;
button[15].start_y = COLOR_BLOCK_HEIGHT*7;
button[15].end_x = BUTTON_START_X + COLOR_BLOCK_WIDTH*2 ;
button[15].end_y = LCD_Y_LENGTH;
button[15].para = 16;
button[15].touch_flag = 0;
button[15].draw_btn = Draw_Shape_Button ;
button[15].btn_command = Command_Select_Brush ;
}
button[0].para 参数用于定位按键,主函数做如下改变,初始化相关外设。
#include "stm32f10x.h"
#include "./usart/bsp_usart.h"
#include "./lcd/bsp_ili9341_lcd.h"
#include "./lcd/bsp_xpt2046_lcd.h"
#include "./flash/bsp_spi_flash.h"
#include "./led/bsp_led.h"
#include "palette.h"
#include
#include "mcu_api.h"
#include "protocol.h"
#include "system.h"
#include "wifi.h"
#include "concrol.h"
extern int MANUAL_FEED_NUM;
char dispBuff[100];
extern int MANUAL_FEED_SUM;
int main(void)
{
//LCD 初始化
ILI9341_Init();
//触摸屏初始化
XPT2046_Init();
//从FLASH里获取校正参数,若FLASH无参数,则使用模式3进行校正
Calibrate_or_Get_TouchParaWithFlash(3,0);
/* USART config */
USART_Config();
LED_GPIO_Config();
EXTIX_Init();
//其中0、3、5、6 模式适合从左至右显示文字,
//不推荐使用其它模式显示文字 其它模式显示文字会有镜像效果
//其中 6 模式为大部分液晶例程的默认显示方向
ILI9341_GramScan ( 3 );
//绘制触摸画板界面
Palette_Init(LCD_SCAN_MODE);
wifi_protocol_init();
GPIO_CONFIG();
LCD_SetFont(&Font8x16);
LCD_SetColors(RED,BLACK);
sprintf(dispBuff,"手动投喂量: %d ",MANUAL_FEED_NUM);
ILI9341_DispString_EN_CH(2*48,2*48,dispBuff);
ILI9341_DisplayStringEx(2*48,0*48,16,16,(uint8_t *)"服务器在线!!!",0);
while ( 1 )
{
wifi_uart_service();//心跳检测
//触摸检测函数,本函数至少10ms调用一次
XPT2046_TouchEvenHandler();
LCD_SetFont(&Font8x16);
LCD_SetColors(RED,BLACK);
sprintf(dispBuff,"总喂食量: %d ",MANUAL_FEED_SUM);
ILI9341_DispString_EN_CH(2*48,1*48,dispBuff);
get_wifi_status(mcu_get_wifi_work_state());
}
}
温湿度采集显示
因为H桥驱动板烧了,在自己的垃圾箱里面翻找替代品的时候发现了以前做毕设遗留下来的DHT11温湿度模块和WS2812灯环,物联网设计嘛,玩啥不是玩呢,都安排上。
页面也更新了:
代码首先要修改按钮的初始化
/**
*
@brief Touch_Button_Init 初始化按钮参数
* @param 无
* @retval 无
*/
void Touch_Button_Init(void)
{
/*第一列,主要为颜色按钮*/
button[0].start_x = BUTTON_START_X;
button[0].start_y = 0;
button[0].end_x = BUTTON_START_X+COLOR_BLOCK_WIDTH ;
button[0].end_y = COLOR_BLOCK_HEIGHT;
button[0].para = 1;
button[0].touch_flag = 0;
button[0].draw_btn = Draw_Num_Button ;
button[0].btn_command = Command_Select_Meannum ;
button[1].start_x = BUTTON_START_X;
button[1].start_y = COLOR_BLOCK_HEIGHT;
button[1].end_x = BUTTON_START_X+COLOR_BLOCK_WIDTH ;
button[1].end_y = COLOR_BLOCK_HEIGHT*2;
button[1].para = 2;
button[1].touch_flag = 0;
button[1].draw_btn = Draw_Num_Button ;
button[1].btn_command = Command_Select_Light ;
button[2].start_x = BUTTON_START_X;
button[2].start_y = COLOR_BLOCK_HEIGHT*2;
button[2].end_x = BUTTON_START_X+COLOR_BLOCK_WIDTH ;
button[2].end_y = COLOR_BLOCK_HEIGHT*3;
button[2].para = 3;
button[2].touch_flag = 0;
button[2].draw_btn = Draw_Num_Button ;
button[2].btn_command = Command_Select_Color ;
button[3].start_x = BUTTON_START_X;
button[3].start_y = COLOR_BLOCK_HEIGHT*3;
button[3].end_x = BUTTON_START_X+COLOR_BLOCK_WIDTH ;
button[3].end_y = COLOR_BLOCK_HEIGHT*4;
button[3].para = 4;
button[3].touch_flag = 0;
button[3].draw_btn = Draw_Num_Button ;
button[3].btn_command = Command_Select_Color ;
button[4].start_x = BUTTON_START_X;
button[4].start_y = COLOR_BLOCK_HEIGHT*4;
button[4].end_x = BUTTON_START_X+COLOR_BLOCK_WIDTH ;
button[4].end_y = COLOR_BLOCK_HEIGHT*5;
button[4].para = 5;
button[4].touch_flag = 0;
button[4].draw_btn = Draw_Num_Button ;
button[4].btn_command = Command_Select_Color ;
button[5].start_x = BUTTON_START_X;
button[5].start_y = COLOR_BLOCK_HEIGHT*5;
button[5].end_x = BUTTON_START_X+COLOR_BLOCK_WIDTH ;
button[5].end_y = COLOR_BLOCK_HEIGHT*6;
button[5].para = 6;
button[5].touch_flag = 0;
button[5].draw_btn = Draw_Num_Button ;
button[5].btn_command = Command_Select_Color ;
button[6].start_x = BUTTON_START_X;
button[6].start_y = COLOR_BLOCK_HEIGHT*6;
button[6].end_x = BUTTON_START_X+COLOR_BLOCK_WIDTH ;
button[6].end_y = COLOR_BLOCK_HEIGHT*7;
button[6].para = 7;
button[6].touch_flag = 0;
button[6].draw_btn = Draw_Num_Button ;
button[6].btn_command = Command_Select_Color ;
button[7].start_x = BUTTON_START_X;
button[7].start_y = COLOR_BLOCK_HEIGHT*7;
button[7].end_x = BUTTON_START_X+COLOR_BLOCK_WIDTH ;
button[7].end_y = LCD_Y_LENGTH;
button[7].para = CL_BUTTON_GREY;
button[7].touch_flag = 0;
button[7].draw_btn = Draw_Clear_Button ;
button[7].btn_command = Command_Clear_Palette ;
/*第二列,主要为画刷按钮*/
button[8].start_x = BUTTON_START_X + COLOR_BLOCK_WIDTH;
button[8].start_y = 0;
button[8].end_x = BUTTON_START_X + COLOR_BLOCK_WIDTH*2 ;
button[8].end_y = COLOR_BLOCK_HEIGHT;
button[8].para = 9;
button[8].touch_flag = 0;
button[8].draw_btn = Draw_Num_Button ;
button[8].btn_command = Command_Select_Meannum ;
button[9].start_x = BUTTON_START_X + COLOR_BLOCK_WIDTH;
button[9].start_y = COLOR_BLOCK_HEIGHT;
button[9].end_x = BUTTON_START_X + COLOR_BLOCK_WIDTH*2 ;
button[9].end_y = COLOR_BLOCK_HEIGHT*2;
button[9].para = 10;
button[9].touch_flag = 0;
button[9].draw_btn = Draw_Num_Button ;
button[9].btn_command = Command_Select_Light ;
button[10].start_x =BUTTON_START_X + COLOR_BLOCK_WIDTH;
button[10].start_y = COLOR_BLOCK_HEIGHT*2;
button[10].end_x = BUTTON_START_X + COLOR_BLOCK_WIDTH*2 ;
button[10].end_y = COLOR_BLOCK_HEIGHT*3;
button[10].para = 11;
button[10].touch_flag = 0;
button[10].draw_btn = Draw_Shape_Button ;
button[10].btn_command = Command_Select_Brush ;
button[11].start_x = BUTTON_START_X + COLOR_BLOCK_WIDTH;
button[11].start_y = COLOR_BLOCK_HEIGHT*3;
button[11].end_x = BUTTON_START_X + COLOR_BLOCK_WIDTH*2 ;
button[11].end_y = COLOR_BLOCK_HEIGHT*4;
button[11].para = 12;
button[11].touch_flag = 0;
button[11].draw_btn = Draw_Shape_Button ;
button[11].btn_command = Command_Select_Brush ;
button[12].start_x = BUTTON_START_X + COLOR_BLOCK_WIDTH;
button[12].start_y = COLOR_BLOCK_HEIGHT*4;
button[12].end_x = BUTTON_START_X + COLOR_BLOCK_WIDTH*2 ;
button[12].end_y = COLOR_BLOCK_HEIGHT*5;
button[12].para = 13;
button[12].touch_flag = 0;
button[12].draw_btn = Draw_Shape_Button ;
button[12].btn_command = Command_Select_Brush ;
button[13].start_x = BUTTON_START_X + COLOR_BLOCK_WIDTH;
button[13].start_y = COLOR_BLOCK_HEIGHT*5;
button[13].end_x = BUTTON_START_X + COLOR_BLOCK_WIDTH*2 ;
button[13].end_y = COLOR_BLOCK_HEIGHT*6;
button[13].para = 14;
button[13].touch_flag = 0;
button[13].draw_btn = Draw_Shape_Button ;
button[13].btn_command = Command_Select_Brush ;
button[14].start_x = BUTTON_START_X + COLOR_BLOCK_WIDTH;
button[14].start_y = COLOR_BLOCK_HEIGHT*6;
button[14].end_x = BUTTON_START_X + COLOR_BLOCK_WIDTH*2 ;
button[14].end_y = COLOR_BLOCK_HEIGHT*7;
button[14].para = 15;
button[14].touch_flag = 0;
button[14].draw_btn = Draw_Shape_Button ;
button[14].btn_command = Command_Select_Brush ;
button[15].start_x = BUTTON_START_X + COLOR_BLOCK_WIDTH;
button[15].start_y = COLOR_BLOCK_HEIGHT*7;
button[15].end_x = BUTTON_START_X + COLOR_BLOCK_WIDTH*2 ;
button[15].end_y = LCD_Y_LENGTH;
button[15].para = 16;
button[15].touch_flag = 0;
button[15].draw_btn = Draw_Shape_Button ;
button[15].btn_command = Command_Select_Brush ;
}
button[0].para 参数用于定位按键,主函数做如下改变,初始化相关外设。
#include "stm32f10x.h"
#include "./usart/bsp_usart.h"
#include "./lcd/bsp_ili9341_lcd.h"
#include "./lcd/bsp_xpt2046_lcd.h"
#include "./flash/bsp_spi_flash.h"
#include "./led/bsp_led.h"
#include "palette.h"
#include
#include "mcu_api.h"
#include "protocol.h"
#include "system.h"
#include "wifi.h"
#include "concrol.h"
extern int MANUAL_FEED_NUM;
char dispBuff[100];
extern int MANUAL_FEED_SUM;
int main(void)
{
//LCD 初始化
ILI9341_Init();
//触摸屏初始化
XPT2046_Init();
//从FLASH里获取校正参数,若FLASH无参数,则使用模式3进行校正
Calibrate_or_Get_TouchParaWithFlash(3,0);
/* USART config */
USART_Config();
LED_GPIO_Config();
EXTIX_Init();
//其中0、3、5、6 模式适合从左至右显示文字,
//不推荐使用其它模式显示文字 其它模式显示文字会有镜像效果
//其中 6 模式为大部分液晶例程的默认显示方向
ILI9341_GramScan ( 3 );
//绘制触摸画板界面
Palette_Init(LCD_SCAN_MODE);
wifi_protocol_init();
GPIO_CONFIG();
LCD_SetFont(&Font8x16);
LCD_SetColors(RED,BLACK);
sprintf(dispBuff,"手动投喂量: %d ",MANUAL_FEED_NUM);
ILI9341_DispString_EN_CH(2*48,2*48,dispBuff);
ILI9341_DisplayStringEx(2*48,0*48,16,16,(uint8_t *)"服务器在线!!!",0);
while ( 1 )
{
wifi_uart_service();//心跳检测
//触摸检测函数,本函数至少10ms调用一次
XPT2046_TouchEvenHandler();
LCD_SetFont(&Font8x16);
LCD_SetColors(RED,BLACK);
sprintf(dispBuff,"总喂食量: %d ",MANUAL_FEED_SUM);
ILI9341_DispString_EN_CH(2*48,1*48,dispBuff);
get_wifi_status(mcu_get_wifi_work_state());
}
}
温湿度采集显示
因为H桥驱动板烧了,在自己的垃圾箱里面翻找替代品的时候发现了以前做毕设遗留下来的DHT11温湿度模块和WS2812灯环,物联网设计嘛,玩啥不是玩呢,都安排上。
页面也更新了:
举报