Newbie to the OLED trying to add to my project

Im trying to add a OLED display that will display a number for just the button that was pressed... this is just the code




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

// configure buttons
OneButton button1(2, true, true);
OneButton button2(3, true, true);
OneButton button3(4, true, true);
OneButton button4(5, true, true);


// Create and bind the MIDI interface to the default hardware Serial port
MIDI_CREATE_DEFAULT_INSTANCE();

void setup() {
  // button 1
  button1.attachClick(button1Press);
  button1.attachDoubleClick(doubleclick1);
  button1.attachLongPressStart(button1LongPressStart);

  // button 2
  button2.attachClick(button2Press);
  button2.attachDoubleClick(doubleclick2);
  button2.attachLongPressStart(button2LongPressStart);

  // button 3
  button3.attachClick(button3Press);
  button3.attachDoubleClick(doubleclick3);
  button3.attachLongPressStart(button3LongPressStart);

  // button 4
  button4.attachClick(button4Press);
  button4.attachLongPressStart(button4LongPressStart);

 
  // MIDI setup
  MIDI.begin();
}


void loop() {
  button1.tick();
  button2.tick();
  button3.tick();
  button4.tick();

  // TODO: do we need the delay here as in the example?
}

// button 1 Events
void button1Press() {
  // Snapshot 1
  MIDI.sendControlChange(69, 0, 1);
}

void doubleclick1() {
  //FS 5
  MIDI.sendControlChange(53, 1, 1);
} 
 
void button1LongPressStart() {
  // Preset Dwn
  MIDI.sendControlChange(72, 0, 1);
}

// button 2 Events
void button2Press() {
  // Snapshot 2
  MIDI.sendControlChange(69, 1, 1);
}

void doubleclick2() {
  //FS 4
  MIDI.sendControlChange(52, 1, 1);
} 

void button2LongPressStart() {
  // Preset Up
  MIDI.sendControlChange(72, 127, 1);
}

// button 3 Events
void button3Press() {
  // Snapshot 3
  MIDI.sendControlChange(69, 2, 1);
}

void doubleclick3() {
  //Prev Mode
  MIDI.sendControlChange(71, 5, 1);
} 


void button3LongPressStart() {
  // Next Mode
  MIDI.sendControlChange(71, 4, 1);
}


// button 4 Events
void button4Press() {
  // Tap tempo
  MIDI.sendControlChange(69, 3, 1);
}


void button4LongPressStart() {
  // show tuner
  MIDI.sendControlChange(68, 0, 1);
}
 

Have you tried getting just the OLED display to function, preferably with code you did not write or mess with?

What wiring advice did you find for the OLED?

The sketch you posted does nothing with the OLED, it's not clearwhat point in that sketch you want a number to appear there?

a7

Ive been messing with code that shows bank changes but I’m trying to add code that shows just the buttons press ie 1,2,3,4… seems like it should be simple but apparently not.. the code is what I’m working with .. if some could help me add code for the display that would be appreciated

You can find this anywhere on the internet, but here is the minimum you will need to get some text on the SSD1306 OLED screen:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h> // OLED graphics library
#include <Adafruit_SSD1306.h> // OLED hardware library

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

#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display (SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // create an instance of Adafruit_SSD1406

void setup() {
  Serial.begin(115200); // start Serial Monitor for debugging

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) // start the OLED with its I2C address
  { Serial.println(F("SSD1306 allocation failed"));
    while (1);
  } // OLED init failed. HALT.

  display.clearDisplay(); // clearing the display - not required
  display.setTextSize(1); // set text size 1 - 5
  display.setTextColor(WHITE); // set text color (WHITE and BLACK are the only colors)
  display.setCursor(0, 0); // set cursor location
  display.println("Hello, World!"); 
  display.display(); // this must be called to display the information in the screen buffer
}

void loop(){
  // add your code
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.