讓菜單循環播放只要用到的函數
void rotateRight(uint8_t *arr[], int n);讓數組右移
void rotateLeft( uint8_t *arr[], int n);讓數組左移
int ui_run(int *a,int *a_tag,uint8_t speed,uint8_t slow_cnt);設置菜單移動以及移動速度,返回值為bool放在while循環里使用。
首先我們要創建一個指針數組存放我們圖片的指針地址uint8_t *p[]={bmp_img,bmp_clock,bmp_gear,bmp_led,bmp_pin};
因為u8g2_DrawXBMP(); 函數畫圖需要的是我們圖片的地址而不是整個圖片數組。
下面是源碼:
int ui_run(int *a,int *a_tag,uint8_t speed,uint8_t slow_cnt) //UI滑動效果放入while里
int ui_run(int *a,int *a_tag,uint8_t speed,uint8_t slow_cnt)
{
uint8_t temp;
temp = abs(*a_tag - *a) > slow_cnt ? speed : 1;
if(*a < *a_tag)
{
*a += temp;
}
else if (*a > *a_tag)
{
*a -= temp;
}
else
{
return 0;
}
return 1;
}
#include
void rotateRight( uint8_t *arr[], int n) {
uint8_t *temp= arr[n-1]; // 保存最后一個元素
for (int i = n-1; i > 0; i--) {
arr[i] = arr[i-1]; // 右移元素
}
arr[0] = temp; // 將保存的最后一個元素放到第一個位置
}
void rotateLeft( uint8_t *arr[], int n) {
uint8_t *temp= arr[0]; // 保存第一個元素
for (int i = 0; i > n-1; i++) {
arr[i] = arr[i+1]; // 左移元素
}
arr[n-1] = temp; // 將保存的元素放到最后位置
}
while (1)
{
Coordinate.Menu_x=8;
while(ui_run(&Coordinate.Menu_x,&meun,Coordinate.speed,Coordinate.Lspeed) )
{
u8g2_DrawXBMP(&u8g2,Coordinate.Menu_x-80,Coordinate.Menu_y,32,32,p[0]);
u8g2_DrawXBMP(&u8g2,Coordinate.Menu_x-40,Coordinate.Menu_y,32,32,p[1]);
u8g2_DrawXBMP(&u8g2,Coordinate.Menu_x,Coordinate.Menu_y,32,32,p[2]);
u8g2_DrawXBMP(&u8g2,Coordinate.Menu_x+40,Coordinate.Menu_y,32,32,p[3]);
u8g2_DrawXBMP(&u8g2,Coordinate.Menu_x+80,Coordinate.Menu_y,32,32,p[4]);
u8g2_SendBuffer(&u8g2);
u8g2_ClearBuffer(&u8g2);
}
rotateRight(p,5);
HAL_Delay(2000);
//u8g2_ClearBuffer(&u8g2);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
-
STM32
+關注
關注
2289文章
11011瀏覽量
362238 -
u8g2
+關注
關注
0文章
18瀏覽量
2099
發布評論請先 登錄
【CH32V208開發板】圖形庫u8g2的oled顯示
怎樣去使用NodeMCU的U8G2庫呢
oled—u8g2庫使用說明
【平頭哥RVB2601創意應用開發】實踐2-移植U8g2圖形庫
NodeMCU 之 U8G2 庫使用詳解

esp8266學習筆記⑨:OLED 屏幕的使用(u8g2圖形庫模塊)

ESP8266驅動SH1306-1.3寸OLED屏幕(u8g2圖形庫)

關于stm32,u8g2菜單之間切換(二)u8g2的移植

關于stm32,u8g2菜單之間切換(三)寫u8g2的一些必要函數

評論