Creare un menù 4 pulsanti con OLED SSD1306

Buongiorno,
ho trovato quest'esempio però non risponde ai comandi dei miei tasti. Come mai?

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 12
Adafruit_SSD1306 display(OLED_RESET);


const int enter = D5;
const int up = D7;
const int down = D6;
const int back = D8;
int start = 1;
int run = 0;
int sel = 0;
int sub = 0;
void screen(unsigned char x);

void setup()
{

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();

  Serial.begin(115200); // initialize serial communication at 115200 baud

  pinMode(enter, INPUT);
  pinMode(up, INPUT);
  pinMode(down, INPUT);
  pinMode(back, INPUT);

  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(20, 20);

  display.println("LOADING");
  Serial.println("LOADING");
  display.display();
  delay(500);
  display.setCursor(100, 20);
  display.print(".");
  display.display();
  delay(500);
  display.setCursor(105, 20);
  display.print(".");
  display.display();
  delay(500);
  display.setCursor(110, 20);
  display.print(".");
  display.display();
  delay(1000);
  display.setTextSize(1);
}


void loop()
{

  screen('a');
  while (start == 1)
  {
    if (digitalRead(enter) == HIGH)
    {
      screen('b');
      run = 1;
      start = 0;
      sel = 0;

    }

    else
    {
      run = 0;
      start = 1;
      sel = 0;

    }
  }

  while (run == 1)
  {

    if (digitalRead(enter) == HIGH)
    {
      screen('d');
      sel = 1;
    } while (digitalRead(enter) == HIGH);

    if ((digitalRead(up) == HIGH) || (digitalRead(down) == HIGH))
    {
      screen('c');
      run = 2;
    } while ((digitalRead(up) == HIGH) || (digitalRead(down) == HIGH));

    if (digitalRead(back) == HIGH)
    {
      screen('a');
      sel = 0;
      run = 0;
      start = 1;

    } while (digitalRead(back) == HIGH);
  }

  while (run == 2)
  {

    if (digitalRead(enter) == HIGH)
    {
      screen('f');
      sel = 2;

    } while (digitalRead(enter) == HIGH);

    if ((digitalRead(up) == HIGH) || (digitalRead(down) == HIGH))
    {
      screen('b');
      run = 1;
    } while ((digitalRead(up) == HIGH) || (digitalRead(down) == HIGH));

    if (digitalRead(back) == HIGH)
    {
      screen('a');
      sel = 0;
      run = 0;
      start = 1;
    } while (digitalRead(back) == HIGH);
  }

  while (sel == 1)
  {

    if (digitalRead(enter) == HIGH)
    {
      screen('g');
      sub = 1;
    } while (digitalRead(enter) == HIGH);

    if ((digitalRead(up) == HIGH) || (digitalRead(down) == HIGH))
    {
      screen('e');
      sel = 3;

    } while ((digitalRead(up) == HIGH) || (digitalRead(down) == HIGH));

    if (digitalRead(back) == HIGH)
    {
      screen('b');
      sel = 0;
      run = 1;
      sub = 0;
    }  while (digitalRead(back) == HIGH);
  }


  while (sel == 2)
  {

    if (digitalRead(enter) == HIGH)
    {
      screen('i');
    } while (digitalRead(enter) == HIGH);

    if ((digitalRead(up) == HIGH) || (digitalRead(down) == HIGH))
    {
      while ((digitalRead(up) == HIGH) || (digitalRead(down) == HIGH));
    }

    if (digitalRead(back) == HIGH)
    {
      screen('c');
      sel = 0;
      run = 2;
      sub = 0;

    } while (digitalRead(back) == HIGH);
  }

  while (sel == 3)
  {

    if (digitalRead(enter) == HIGH)
    {
      screen('h');
      sub = 2;
    } while (digitalRead(enter) == HIGH);

    if ((digitalRead(up) == HIGH) || (digitalRead(down) == HIGH))
    {
      screen('d');
      sel = 1;

    } while ((digitalRead(up) == HIGH) || (digitalRead(down) == HIGH));

    if (digitalRead(back) == HIGH)
    {
      screen('b');
      run = 1;

    } while (digitalRead(back) == HIGH);
  }


}

void screen(unsigned char x)
{
  switch (x)
  {

    case 'a':
      display.clearDisplay();
      display.setCursor(40, 2);
      display.println("welcome");
      delay(800);
      display.setCursor(20, 20);
      display.println("Press ENTER to");
      display.setCursor(35, 30);
      display.println("continue");
      display.display();
      Serial.print ("Mostro menù A");
      break;

    case 'b':
      display.clearDisplay();
      display.setCursor(0, 0);
      display.println("1> CASE B   <");
      display.display();
      delay(1000);
      display.clearDisplay();
      Serial.println ("Mostro menù B");
      break;

    case 'c':
      display.clearDisplay();
      display.setCursor(0, 0);
      display.println("1> CASE C");
      display.display();
      Serial.println ("Mostro menù C");
      break;


    case 'd':
      display.clearDisplay();
      display.setCursor(0, 0);
      display.println("1> CASE D  < ");
      display.display();
      Serial.println ("Mostro menù D");
      break;

    case 'e':
      display.clearDisplay();
      display.setCursor(0, 0);
      display.println("1> CASE E ");
      display.display();
      Serial.println ("Mostro menù E");
      break;


    case 'f':
      display.clearDisplay();
      display.setCursor(0, 0);
      display.println("1> CASE F ");
      display.display();
      Serial.println ("Mostro menù F");
      break;

    case 'g':
      display.clearDisplay();
      display.setCursor(0, 0);
      display.println("CASE G");
      display.display();
      Serial.println ("Mostro menù G");
      break;

    case 'h':
      display.clearDisplay();
      display.setCursor(0, 0);
      display.println("CASE H");
      display.display();
      Serial.println ("Mostro menù H");
      break;
  }
}

S'intende che la pulsantiera funziona correttamente e l'ho testata con questo codice:

#include "Wire.h"
#include "Adafruit_GFX.h"
#include "OakOLED.h"


/////// GLOBALS //////

OakOLED oled;

///////////////////////

const int buttonOK = D5;     // number of pushbutton 1 pin OK
int buttonStateOK = LOW;       // set the default variable value for pushbutton1 status
const int buttonDOWN = D6;     // number of pushbutton 2 pin GIU'
int buttonStateDOWN = LOW;       // set the default variable value for pushbutton2 status
const int buttonUP = D7;     // number of pushbutton 3 pin SU'
int buttonStateUP = LOW;       // set the default variable value for pushbutton3 status
const int buttonESC = D8;     // number of pushbutton 4 pin ESC
int buttonStateESC = LOW;       // set the default variable value for pushbutton4 status



void setup() {                  // Set Pins to Outputs Or Inputs
  pinMode(buttonOK, INPUT);   // initialize the pushbutton pins as an inputs:
  pinMode(buttonDOWN, INPUT);   // initialize the pushbutton pins as an inputs:
  pinMode(buttonUP, INPUT);   // initialize the pushbutton pins as an inputs:
  pinMode(buttonESC, INPUT);   // initialize the pushbutton pins as an inputs:

  Serial.begin(115200); // initialize serial communication at 115200 baud
  oled.begin();
  oled.setTextSize(1);
  oled.setTextColor(1);

  oled.setCursor(30, 0);
  oled.clearDisplay();
  oled.print("TEST BUTTON");
  oled.setCursor(0, 25);
  oled.print("WAIT A BUTTON PRESS");
  oled.display();
  Serial.println("WAIT A BUTTON PRESS");
  delay(5000);
}


void loop() {
  buttonStateOK = digitalRead(buttonOK);  // read current states of the pushbutton value:
  buttonStateDOWN = digitalRead(buttonDOWN);  // read current states of the pushbutton value:
  buttonStateUP = digitalRead(buttonUP);  // read current states of the pushbutton value:
  buttonStateESC = digitalRead(buttonESC);  // read current states of the pushbutton value:

  // check if the pushbutton is pressed buttonState# == HIGH/LOW
  // if pressed change buttonState == HIGH to turn on ledPin#
  // else if buttonState == LOW then digitalWrite(ledPin#, LOW) Keeps Led off.


  if (buttonStateOK == HIGH) {    //check buttonState
    oled.setCursor(30, 0);
    oled.clearDisplay();
    oled.print("TEST BUTTON");
    oled.setCursor(0, 25);
    oled.println("BUTTON PRESSED:");
    oled.print("    D5 - OK");
    oled.display();
    Serial.println("BUTTON PRESSED: D5 - OK"); //Print buttonState to serial
    delay(200);
  }

  if (buttonStateDOWN == HIGH) {   //check buttonState
    oled.setCursor(30, 0);
    oled.clearDisplay();
    oled.print("TEST BUTTON");
    oled.setCursor(0, 25);
    oled.println("BUTTON PRESSED:");
    oled.print("    D6 - DOWN");
    oled.display();
    Serial.println("BUTTON PRESSED: D6 - DOWN"); //Print buttonState to serial
    oled.display();
    delay(200);
  }

  if (buttonStateUP == HIGH) {   //check buttonState
    oled.setCursor(30, 0);
    oled.clearDisplay();
    oled.print("TEST BUTTON");
    oled.setCursor(0, 25);
    oled.println("BUTTON PRESSED:");
    oled.print("    D7 - UP");
    oled.display();
    Serial.println("BUTTON PRESSED: D7 - UP"); //Print buttonState to serial
    oled.display();
    delay(200);
  }
  if (buttonStateESC == HIGH) {   //check buttonState
    oled.setCursor(30, 0);
    oled.clearDisplay();
    oled.print("TEST BUTTON");      //Cancella Schermo lcd
    oled.setCursor(0, 25);
    oled.println("BUTTON PRESSED:");
    oled.print("    D8 - ESC");
    oled.display();
    Serial.println("BUTTON PRESSED: D8 - ESC"); //Print buttonState to serial
    oled.display();
    delay(200);
  }

  oled.setCursor(30, 0);
  oled.clearDisplay();
  oled.print("TEST BUTTON");
  oled.setCursor(0, 25);
  oled.print("ALL BUTTONS RELEASED");
  oled.display();
}

ho trovato quest'esempio però non risponde ai comandi dei miei tasti. Come mai?

#define OLED_RESET 12

Corrisponde al pin D6, prova a cambiarlo

brunello22:

#define OLED_RESET 12

Corrisponde al pin D6, prova a cambiarlo

impostato sia come

#define OLED_RESET 0

che come

#define OLED_RESET D0

ma non cambia nulla

Domanda: Ma hai messo delle resistenze verso il GND ( PullDown ) sui pulsanti ?

brunello22:
Domanda: Ma hai messo delle resistenze verso il GND ( PullDown ) sui pulsanti ?

Si da 10k per ogni pulsante.

Se leggi bene però uso la wemos, non sò se è queto il problema