分享一个2X4的图标菜单(摇杆控制)的代码-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2127|回复: 0

分享一个2X4的图标菜单(摇杆控制)的代码

[复制链接]
发表于 2019-12-14 16:12 | 显示全部楼层 |阅读模式
通过摇杆控制选择需要移动到的菜单,可以根据个人需求定制每个图标不同的内容,屏幕用的I2C12864OLED屏,操作流畅,分享给大家,做项目可以改,界面里的图标是28*28大小的,可以根据自己需要修改图标代码






#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_FAST); // Dev 0, Fast I2C / TWI

//摇杆X轴连接A0,Y轴连接A1

int Frame_position_x ;
int Frame_position_y ;

static unsigned char bitmap[][112] U8G_PROGMEM = {
  {0X00,0XF8,0X03,0X00,0X00,0XFE,0X0F,0X00,0X80,0X07,0X3C,0X00,0XE0,0X00,0XE0,0X00,
0X70,0XE0,0XC0,0X01,0X38,0XF8,0X83,0X03,0X18,0XFC,0X07,0X03,0X0C,0XFC,0X0F,0X06,
0X04,0XFE,0X0F,0X04,0X06,0XFE,0X0F,0X0C,0X06,0XFE,0X0F,0X0C,0X03,0XFE,0X0F,0X08,
0X03,0XFC,0X07,0X08,0X03,0XFE,0X0F,0X08,0X03,0XFE,0X07,0X08,0X03,0XFC,0X07,0X08,
0X03,0XF8,0X03,0X08,0X03,0XF8,0X03,0X08,0X06,0XF0,0X01,0X0C,0X06,0XF0,0X01,0X0C,
0X04,0XF8,0X03,0X04,0X0C,0XFC,0X07,0X06,0X18,0XFF,0X1F,0X03,0XF8,0XFF,0XFF,0X01,
0XF0,0XFF,0XFF,0X01,0XC0,0XFF,0X7F,0X00,0X80,0XFF,0X3F,0X00,0X00,0XFE,0X0F,0X00
},
{ 0X00,0X00,0X00,0X00,0X00,0X40,0X00,0X00,0XE0,0XE3,0XFC,0X00,0XF0,0XEF,0XFE,0X01,
0XF8,0X4F,0XFE,0X03,0XFC,0XF3,0XF9,0X07,0XFC,0XFE,0XF7,0X07,0X7C,0XFF,0XDF,0X07,
0XBC,0XBF,0XBF,0X07,0XDC,0X47,0X7C,0X07,0XFC,0XE1,0X70,0X03,0XE8,0XE1,0XF0,0X02,
0XF0,0XE0,0XE0,0X00,0XF0,0XE0,0XE0,0X01,0X70,0XE0,0XE3,0X01,0X70,0XE0,0XC7,0X01,
0X70,0XE0,0XE7,0X01,0XF0,0X00,0XE0,0X01,0XF0,0X00,0XE0,0X01,0XE0,0X00,0XF0,0X00,
0XE0,0X01,0XF0,0X00,0XC0,0X03,0X7C,0X00,0X80,0X1F,0X3F,0X00,0X00,0XFF,0X1F,0X00,
0X80,0XFF,0X3F,0X00,0X80,0XFB,0X3B,0X00,0X80,0X01,0X30,0X00,0X00,0X00,0X00,0X00
},
{ 0X00,0X02,0X0E,0X00,0X00,0X02,0X1B,0X00,0X40,0X90,0X35,0X00,0X00,0X8F,0X2E,0X00,
0X80,0X88,0X2A,0X00,0XA0,0XA8,0X2A,0X00,0X80,0X88,0X2A,0X00,0X00,0X87,0X0A,0X00,
0X40,0X90,0X6A,0X00,0X00,0X82,0X6A,0X00,0X00,0X80,0X6A,0X00,0X00,0X80,0X6A,0X00,
0X00,0X80,0X0A,0X00,0X00,0X80,0X6A,0X00,0X00,0X80,0X0A,0X00,0X00,0X80,0X6A,0X00,
0X00,0X80,0X0A,0X00,0X00,0X80,0X2A,0X00,0X00,0XC0,0X6A,0X00,0X00,0X60,0XDB,0X00,
0X00,0XA0,0XA0,0X00,0X00,0XA0,0XE0,0X00,0X00,0XF0,0XC0,0X01,0X00,0XE0,0XE0,0X01,
0X00,0XA0,0XA0,0X00,0X00,0X60,0XDB,0X00,0X00,0XC0,0X6E,0X00,0X00,0X80,0X3B,0X00
},
{ 0X00,0XF0,0X01,0X00,0X00,0XF0,0X01,0X00,0X00,0XF0,0X01,0X00,0XC0,0XB8,0X63,0X00,
0XE0,0X1F,0XFF,0X00,0XF0,0X07,0XFC,0X01,0X38,0X01,0X90,0X03,0X38,0X00,0X80,0X03,
0X70,0X00,0XC0,0X01,0X30,0X40,0X80,0X01,0X30,0XF8,0X81,0X01,0X18,0X0C,0X02,0X03,
0X1F,0X04,0X04,0X0F,0X0F,0X04,0X04,0X0E,0X03,0X06,0X0C,0X0C,0X0F,0X04,0X04,0X0E,
0X1F,0X04,0X04,0X0F,0X18,0X08,0X02,0X03,0X30,0XF0,0X81,0X01,0X30,0X40,0X80,0X01,
0X70,0X00,0XC0,0X01,0X38,0X00,0X80,0X03,0X38,0X01,0X90,0X03,0XF0,0X07,0XFC,0X01,
0XE0,0X1F,0XFF,0X00,0XC0,0XB8,0X63,0X00,0X00,0XF0,0X01,0X00,0X00,0XF0,0X01,0X00
},
{ 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XFE,0XFF,0XFF,0X0F,
0XFF,0XFF,0XFF,0X0F,0XFF,0XFF,0XFF,0X0F,0X07,0X00,0X00,0X0C,0X07,0X00,0X00,0X0C,
0X87,0X01,0X00,0X0C,0XC7,0X03,0X00,0X0C,0XC7,0X07,0X00,0X0C,0XC7,0X03,0X00,0X0C,
0X87,0X03,0X0C,0X0C,0X07,0X00,0X0E,0X0C,0X07,0X00,0X1F,0X0C,0X07,0X00,0X1F,0X0C,
0X07,0X83,0X3F,0X0C,0X07,0XC7,0X3F,0X0C,0X87,0XEF,0X7F,0X0C,0XC7,0XFF,0XFF,0X0C,
0XE7,0XFF,0XFF,0X0C,0XE7,0XFF,0XFF,0X0D,0XF7,0XFF,0XFF,0X0D,0X07,0X00,0X00,0X0C,
0XFF,0XFF,0XFF,0X0F,0XFE,0XFF,0XFF,0X0F,0XFC,0XFF,0XFF,0X07,0X00,0X00,0X00,0X00
},
{ 0X00,0X3F,0X00,0X00,0XC0,0XFF,0X00,0X00,0XF0,0XFF,0X03,0X00,0XF8,0XF3,0X07,0X00,
0X7C,0X80,0X0F,0X00,0X3C,0X07,0X0F,0X00,0XDE,0X07,0X1E,0X00,0XCE,0X01,0X1C,0X00,
0XEF,0X00,0X3C,0X00,0X6F,0X00,0X3C,0X00,0X67,0X00,0X3C,0X00,0X07,0X00,0X3C,0X00,
0X0F,0X00,0X3C,0X00,0X0F,0X00,0X3C,0X00,0X0E,0X00,0X1C,0X00,0X1E,0X00,0X1E,0X00,
0X3C,0X00,0X0F,0X00,0X7C,0X80,0X0F,0X00,0XF8,0XFF,0X77,0X00,0XF0,0XFF,0XFB,0X00,
0XC0,0XFF,0XFC,0X01,0X00,0X3F,0XFC,0X03,0X00,0X00,0XFC,0X07,0X00,0X00,0XF8,0X0F,
0X00,0X00,0XF0,0X0F,0X00,0X00,0XE0,0X0F,0X00,0X00,0XC0,0X0F,0X00,0X00,0X80,0X0F
},
{ 0XC0,0X01,0X70,0X00,0XC0,0X01,0X70,0X00,0XC0,0X01,0X70,0X00,0XC0,0X01,0X70,0X00,
0XDC,0XFD,0X77,0X07,0XDE,0XFD,0X77,0X0F,0X3F,0XFE,0X8F,0X0F,0XFF,0XFF,0XFF,0X0F,
0XFF,0XFF,0XFF,0X0F,0X07,0X00,0X00,0X0C,0X03,0X00,0X00,0X08,0X03,0X00,0X00,0X08,
0X03,0X00,0X00,0X08,0XC3,0XE1,0X70,0X08,0XC3,0XE1,0X70,0X08,0XC3,0XE1,0X70,0X08,
0X03,0X00,0X00,0X08,0X03,0X00,0X00,0X08,0X03,0X00,0X00,0X08,0X03,0X00,0X00,0X08,
0XC3,0XE1,0X70,0X08,0XC3,0XE1,0X70,0X08,0XC3,0XE1,0X70,0X08,0X03,0X00,0X00,0X08,
0X03,0X00,0X00,0X08,0X03,0X00,0X00,0X08,0X06,0X00,0X00,0X0C,0XFC,0XFF,0XFF,0X07
},
{ 0X00,0X40,0X00,0X00,0X00,0XE0,0X00,0X00,0X00,0XE0,0X00,0X00,0X00,0XF0,0X01,0X00,
0X00,0XB8,0X03,0X00,0X00,0X18,0X03,0X00,0X00,0X1C,0X07,0X00,0XFC,0XFF,0XFF,0X07,
0XFC,0XFF,0XFF,0X07,0X1C,0X07,0X1C,0X07,0X18,0X03,0X18,0X03,0XB0,0X03,0XB8,0X01,
0XF0,0X01,0XF0,0X01,0XE0,0X00,0XE0,0X00,0XE0,0X00,0XE0,0X00,0XE0,0X00,0XE0,0X00,
0XF0,0X01,0XF0,0X01,0XB8,0X03,0XB8,0X01,0X18,0X03,0X18,0X03,0X1C,0X07,0X1C,0X07,
0XFC,0XFF,0XFF,0X07,0XFC,0XFF,0XFF,0X07,0X00,0X1C,0X07,0X00,0X00,0X18,0X03,0X00,
0X00,0XB8,0X01,0X00,0X00,0XF0,0X01,0X00,0X00,0XE0,0X00,0X00,0X00,0XE0,0X00,0X00
},
};


void draw(void) {
  unsigned char i;
  unsigned char j;

  u8g.firstPage();  
  do {
      for(i=0;i<2;i++)
      {
        for(j=0;j<4;j++)
        {
         u8g.drawXBMP( 32*j+1, 32*i+2,28, 28, bitmap[4*i+j]);
        }
      }
      u8g.drawRFrame(Frame_position_x,Frame_position_y, 30,32,5);
      } while( u8g.nextPage() );

}

void key_scan(void)
{
  int x_value;
  int y_value ;

  x_value = analogRead(A0);
  y_value = analogRead(A1);

    if(x_value>800)
      {
        delay(100);
        if(x_value> 800)
        {
           Frame_position_x = Frame_position_x+32;
           if(Frame_position_x>96)
           {
              Frame_position_x = 96;
            }
        }
      }
      if(x_value<300)
      {
        delay(100);
        if(x_value<300)
        {
           Frame_position_x = Frame_position_x-32;
           if(Frame_position_x<0)
           {
              Frame_position_x = 0;
            }
        }
      }

      if(y_value>800)
      {
        delay(100);
        if(y_value> 800)
        {
           Frame_position_y = Frame_position_y+32;
           if(Frame_position_y>32)
           {
              Frame_position_y = 32;
            }
        }
      }
      if(y_value<300)
      {
        delay(100);
        if(y_value<300)
        {
           Frame_position_y = Frame_position_y-32;
           if(Frame_position_y<0)
           {
              Frame_position_y = 0;
            }
        }
      }

  }

void setup(void) {
  Frame_position_x = 0;
  Frame_position_y = 0;
  }

void loop(void) {
  draw();
  key_scan();

}


摇杆可以控制方框移动到需要到的菜单处

摇杆可以控制方框移动到需要到的菜单处
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 11:33 , Processed in 0.142572 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表