I need help using an I2C OLED to display what button presses are doing

Hi All,

I having some problems figuring out how to get an I2C OLED display to show what my button presses are doing.

I’ve made a working RC skid steering robot, and now I’m just looking to upgrade the transmitter.
The transmitter uses PS2 joysticks, and i’m utilizing the pushbutton integrated in each of them.

When the user clicks the left pushbutton, a counter cycles between 0, 1, and 2. The same thing happens when the user clicks the right pushbutton.

I’ve tried oled tests and a couple of menu sketches and all work. But i’m not trying to print a “hello world”, or trying to navigate through a menu. I’m trying say something like…

“if lightmode == 0, then place an arrow beside off”

The oled only has 8 lines, and the best configuration is what i’ve created in photoshop below.

The headings will stay the same, and all menu items will be listed below so that the kids using it will know how many possible items there are.

If anyone can point me in the right direction as to how to make even a similar display appear on my OLED, i’d be very grateful. I’ll post my working robot transmitter code below so you can see what i’m working with. Thanks in advance for the insights!

Here’s the transmitter code i’m working with.

#include <VirtualWire.h>

char Array[30];
int X,Y;

const int buttonPin = 4; //headlight pushbutton on pin 4
const int button2Pin = 7; //headlight pushbutton on pin 4
const int ledPin = 13;      // the number of the LED pin

// Variables will change:
int ledState = LOW;         // the current state of the output pin
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin

int led2State = LOW;         // the current state of the output pin
int button2State;             // the current reading from the input pin
int lastButton2State = LOW;   // the previous reading from the input pin

int val;                        // variable for reading the pin status
int val2;                       // variable for reading the delayed status

int zal;                        // variable for reading the pin status
int zal2;                       // variable for reading the delayed status

int lightMode = 0;              // What mode is the light in?
int driveMode = 0;              // What mode is the light in?

// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers

void setup()
{
  Serial.begin(9600);  // Debugging only
  Serial.println("Sending"); // Debugging only

  // Initialise the IO and ISR
  //vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2000); // Bits per sec
  vw_set_tx_pin(12); //RF sending pin

  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(button2Pin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);

  // set initial LED state 
  digitalWrite(ledPin, ledState);
  buttonState = digitalRead(buttonPin);   // read the initial state
  button2State = digitalRead(button2Pin);   // read the initial state
}

void loop()
{ 
  headLights();
  drive();


  X = analogRead(0);
  Y = analogRead(1);

  sprintf(Array, "%d,%d,%d,%d.",X,Y,lightMode,driveMode);
  vw_send((uint8_t*)Array, strlen(Array)); 
  vw_wait_tx(); 

  /*
   Serial.print(X); // X axis
   Serial.print(", ");
   Serial.print(Y); // Y axis
   Serial.print(", ");
   Serial.print(ledState); // Z axis
   Serial.print(". ");
   Serial.println();
   delay(10);
   */

  Serial.print(lightMode);
  Serial.print(", ");
  Serial.println(driveMode);
  delay(10);

}


void headLights()
{
  val = digitalRead(buttonPin);      // read input value and store it in val
  delay(10);                         // 10 milliseconds is a good amount of time
  val2 = digitalRead(buttonPin);     // read the input again to check for bounces
  if (val == val2) {                 // make sure we got 2 consistant readings!
    if (val != buttonState) {          // the button state has changed!
      if (val == HIGH) {                // check if the button is pressed
        if (lightMode == 0) {          // if its off
          lightMode = 1;               // turn lights on!
        } 
        else {
          if (lightMode == 1) {        // if its on
            lightMode = 2;             // turn it off
          } 
          else {
            if (lightMode == 2) {      // if its off
              lightMode = 0;           // make the lights dependent on the LDR
            }
            }
          }
        }
      }
    }
  }

  void drive()
  {
    zal = digitalRead(button2Pin);      // read input value and store it in val
    delay(10);                         // 10 milliseconds is a good amount of time
    zal2 = digitalRead(button2Pin);     // read the input again to check for bounces
    if (zal == zal2) {                 // make sure we got 2 consistant readings!
      if (zal != button2State) {          // the button state has changed!
        if (zal == HIGH) {                // check if the button is pressed
          if (driveMode == 0) {          // if the user is in control
            driveMode = 1;               // make it mixed control
          } 
          else {
            if (driveMode == 1) {        // if its mixed
              driveMode = 2;             // make it robot control
            } 
            else {
              if (driveMode == 2) {      // if its robot controlled
                driveMode = 0;           // make it user controlled

              }
            }
          }
        }
      }
    }


    buttonState = val;                 // save the new state in our variable
    button2State = zal;                 // save the new state in our variable
  }

Ok it looks like what I want can be achieved by using MenuSystem by Jon Black.

http://blog.humblecoder.com/arduino-menu-system-library/

But can i display 2 menus on the same screen? at the same time?

My biggest fear is that if i set up the menu system to react to the PS2 joystick button clicks and not the actual software counter, what if some button-bouncing happens and the counter and menu display go out of sync!!! So for example, the counter for headlights will 0, the robots headlights will be off, but the display might show ON.

I'll have to fiddle with it and see what i can do. I'll post the results in case anyone else is interested.