Arduino rise piece 15 joystick OLED multi-level menu

Joystick OLED multi-level menu

As more and more demand for human-computer interaction, information embedded devices with screens need to show more and more, more in-depth with the various menu key input, various switching operations. How convenient management switching operation between different menus it? Benpian to introduce achieve multi-level menu ideas through experiments.

Introduction 1. The multi-level menu

In a variety of screen operation, the multi-level menu is a kind of thinking or a fixed programming framework. Simply when the key is triggered, the current taken out according to the key definition interface keys need to jump from the array index, and then to perform a function in response to the index interface.

2. realization

1. First of all, we need to define a structure, the structure typically includes an interface member variable index number, the interface function pointers and variables corresponding to the actual key for index keys stored representation. Wherein the interface index number is the corresponding function pointer.

typedef struct
{
  unsigned char index;
  unsigned char up;
  unsigned char down;
  unsigned char left;
  unsigned char right;
  void (*operation)(void);
} KEY_TABLE;

This experiment defines four buttons, it defines the up, down, left, right four key variables.

2. structure type definitions to define an array of structures, the number of interfaces, the number is the number of elements in the array.

KEY_TABLE table[9] =
{
  {0, 0, 0, 0, 0, (*menu11)},
  {1, 0, 0, 0, 0, (*menu12)},
  {2, 0, 0, 0, 0, (*menu21)},
  {3, 0, 0, 0, 0, (*menu22)},
  {4, 0, 0, 0, 0, (*menu23)},
  {5, 0, 0, 0, 0, (*menu31)},
  {6, 0, 0, 0, 0, (*menu32)},
  {7, 0, 0, 0, 0, (*menu33)},
  {8, 0, 0, 0, 0, (*menu34)},
};

This experiment defines the interface 9, the array elements so as nine, wherein the interface index number from 0 to 8, respectively corresponding to the interface function pointer. A menu available in the present experiment 2, there are three second level menu, the menu has three four.

3. Press the OK button needs to jump each interface index. This step determines the relationship between the switching interface, very important. Before a menu can be switched between the finishing relationship by sketch, the following correlation diagram between the interface 9 as shown in the present experiments.

Multi-level menu structure

A few examples:

The index is 0, i.e. under menu11 interface, determining {0, 0, 0, 0, 0, (* menu11)} values ​​of four key variables:

  • When the up button is pressed, the display menu11 interface, i.e. the interface index is 0, then the time up = 0;
  • When the key is pressed down, the display menu12 interface, i.e. the interface index is 1, then the time down = 1;
  • When the left button is pressed, the display menu11 interface, i.e. the interface index is 0, then the time down = 0;
  • When the right key is pressed, the display menu21 interface, i.e. the interface index is 2, then the time down = 2;

Therefore, to obtain {0, 0, 1, 0, 2, (* menu11)}

5 is in the index, i.e., the interface menu31 determine {5, 0, 0, 0, 0, (* menu31)} values ​​of four key variables:

  • When the up button is pressed, the display menu31 interface, i.e. the interface index is 5, then the time up = 5;
  • When the key is pressed down, the display menu32 interface, i.e. the interface index is 6, then the time down = 6;
  • When the left button is pressed, the display menu21 interface, i.e. the interface index is 2, then the time down = 2;
  • When the right key is pressed, the display menu31 interface, i.e. the interface index is 5, then the time down = 5;

Therefore, to give {5, 5, 6, 2, 5, (* menu31)}

Jump relationship between each interface established according to the actual demand, the following intact structure array variable present experimental situation.

KEY_TABLE table[9] =
{
  {0, 0, 1, 0, 2, (*menu11)},
  {1, 0, 1, 1, 4, (*menu12)},
  {2, 2, 3, 0, 5, (*menu21)},
  {3, 2, 3, 0, 7, (*menu22)},
  {4, 4, 4, 1, 4, (*menu23)},
  {5, 5, 6, 2, 5, (*menu31)},
  {6, 5, 6, 2, 6, (*menu32)},
  {7, 7, 8, 3, 7, (*menu33)},
  {8, 7, 8, 3, 8, (*menu34)},
};

The actual key function corresponding to the return value, obtaining an index number corresponding to a key interface, and then find and execute a corresponding function according to the index number of the interface.

switch (keyValue)//获取按键对应序号
    {
      case 1: funIndex = table[funIndex].right; break;
      case 2: funIndex = table[funIndex].left; break;
      case 3: funIndex = table[funIndex].down; break;
      case 4: funIndex = table[funIndex].up; break;
    }
current = table[funIndex].operation;//根据需要获取对应需要执行的函数
(*current)();//执行获取到的函数

3. Experimental Materials

  • Uno R3 Development Board
  • Supporting USB data cable
  • Bread plate and supporting cables
  • The biaxially module rocker keys
  • OLED display

4. Experimental Procedure

1. The schematic circuit diagram of a building.

VCC OLED screen, GND are connected to 3.3V development board, GND, SDA OLED screen SCL and A4 and A5 are connected to the development board. The biaxially rocker key module VCC, GND 5V development board are connected, GND, X-axis output module, Y-axis output boards are connected to the analog pins A0, A1.

Principle is shown below:

Experimental schematics

Physical connection is shown below:

Physical connection diagram

2. Create a new sketch, copy the code replacement automatically generated code and save it.

Due to the long code, complete code is available at the end of the article.

3. Development Board connector, and set the port number corresponding to the type of boards, for download.

Download

The experimental results

Multi-interface transitions:

Experimental phenomena


No public concern "TonyCode" backstage reply "improvement" to get the text code.
Arduino learning exchange group: 868 283 450
more, I welcome the attention of the public number. Sweep the micro-channel to follow the Fanger Wei code:
Micro channel scan code added public number: TonyCode

Published 63 original articles · won praise 250 · Views 230,000 +

Guess you like

Origin blog.csdn.net/TonyIOT/article/details/104013813