This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

  • 0 voto(s) - 0 Media
  • 1
  • 2
  • 3
  • 4
  • 5
pantalla OLED y menu con encoder
#1
hola a todos.
estoy intentando hacer con una pantalla OLED de 0.96" un menu con tres opciones y dos submenus. El problema que tengo es que una vez en los submenus una vez que selecciono la opción deseada, esta se tendria que hacer una serie de cosas. (basicamente elegir un tiempo.), este último tramo  no se como hacerlo. He de decir que he copiado el codigo y lo he modificado un poquito, por eso no se como acabarlo.
adjunto el código.
a ver si me podeis ayudar un poquito.


Código:
// prueba 3.1 varios menus y pantalla OLED i encoder
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels


//#define NUM_MENU 3

#define OLED_RESET 13

Adafruit_SSD1306 display(OLED_RESET);

#if (SSD1306_LCDHEIGHT != 32)

#error("Height incorrect, please fix Adafruit_SSD1306.h!");

#endif

const char menu1[] PROGMEM = "Fototrampeo";
const char menu2[] PROGMEM = "Droopwater";
const char menu3[] PROGMEM = "star";

const char sub11[] PROGMEM = "Atras";
const char sub12[] PROGMEM = "Retardo disparador";
const char sub13[] PROGMEM = "Tiempo obturando";

const char sub21[] PROGMEM = "Atras";
const char sub22[] PROGMEM = "Retardo disparador2";
const char sub23[] PROGMEM = "Tiempo obturando2";



const char * const menus[] PROGMEM =
{
   menu1,
   menu2,
   menu3,

   sub11, // sub menu for menu1
   sub12,
   sub13,

   sub21, // sub menu for menu2
   sub22,
   sub23,

};
int button_pin = 7;
int button_state = 0;
int button_state_last = 1;
int subMenu = 0;
int NUM_MENU = 3;

int val=-1;
int encoder0PinA = 3;
int encoder0PinB = 4;
int encoder0Pos = 0;
int encoder0PinALast = LOW;
int n = LOW;


void setup() {

 pinMode( button_pin , INPUT_PULLUP);
 
 pinMode (encoder0PinA, INPUT);
 pinMode (encoder0PinB, INPUT);

 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)

 Serial.begin (9600);
}

void loop() {

 button_state = digitalRead( button_pin );

 Serial.println( button_state );


 updateKnob();
 buttonPush();

if( val != encoder0Pos ){
   val = encoder0Pos;
   updateMenu();
   //delay(100);
}
}
void updateKnob()
{
  n = digitalRead(encoder0PinA);
 if ((encoder0PinALast == LOW) && (n == HIGH)) {
   if (digitalRead(encoder0PinB) == LOW) {
      if( encoder0Pos > 0 ){
          encoder0Pos--;
      }else{
          encoder0Pos = NUM_MENU-1;
      }
   } else {
     if( encoder0Pos < (NUM_MENU-1) ){
         encoder0Pos++;
     }else{
         encoder0Pos = 0;
     }
   }
   Serial.print (encoder0Pos);
   Serial.println();
 }
 encoder0PinALast = n;
 
}
void updateMenu(){
 
  display.clearDisplay();

  display.setTextSize(1);
 
 if( subMenu == 0 ){
      drawMenu(0);
 }
 else if( subMenu == 1){
      drawMenu(3);
 }
 else if( subMenu == 2){
      drawMenu(6);
 }
   
  display.display();
 
}
void buttonPush()
{
   if( (button_state == 0) && ( button_state_last != 0) ){
        button_state_last = 0;
       
        if( (subMenu == 0) && ( encoder0Pos == 0)){ // sub menu 1
             
             subMenu = 1;
             NUM_MENU = 3;
             val = -1;
        }
        else if( (subMenu == 0) && ( encoder0Pos == 1)){ // sub menu 2
             
             subMenu = 2;
             NUM_MENU = 3;
             // NUM_MENU = 2;
             val = -1;
        }
        else if( ((subMenu != 0) && ( encoder0Pos == 0)) ){ // Back to main menu
             subMenu = 0;
             NUM_MENU = 3;
             val = -1;
        }
       
       
   }

   
   button_state_last = button_state;
   
}
void drawMenu(int start){
 
  char tBuffer[22];
 
  for(int i=0; i < NUM_MENU;i++){
 
       //display.setCursor(5,(i*20)+5);
       display.setCursor(5,(i*10)+1);
       display.setTextColor(WHITE);
       if( (encoder0Pos) == i ){
         display.setTextColor(BLACK, WHITE);
       }
       display.println(strcpy_P(tBuffer, (char*)pgm_read_word(&(menus[i+start]))));
             
  }
 
}
  Responder


Posibles temas similares…
Tema Autor Respuestas Vistas Último mensaje
  Acelerometro con pantalla oled antonio_gt_9.2 3 1,990 14-11-2016, 10:36 PM
Último mensaje: Miquel
  Pantalla con Arduino Jose_Glez 3 2,449 16-09-2016, 02:07 PM
Último mensaje: Jose_Glez
  Problemas con bibliotecas para pantalla LCD Electromecánico 9 2,456 02-10-2014, 05:55 AM
Último mensaje: Electromecánico