So I am programming an OLED display from my Arduino Uno. I am trying to have a button that switches the different words on the display. (The words are just placeholders for programs as of now.) My program has a button that changes a counter, and an if test to see what the counter is so it can display the appropriate word. The problem is, whenever I press the button, the display turns black and doesn't do anything anymore. When I start/reset the Arduino, it displays TEMPERATURE, but it should say TIME.
#include <OLED_I2C.h>
OLED myOLED(SDA, SCL, 8);
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];
extern uint8_t BigNumbers[];
//constants:
const int buttonPin = 2;
//variables:
byte oldButtonState = HIGH;
int screenNumber = 0;
byte buttonState = 0;
void setup()
{
myOLED.begin();
myOLED.setFont(SmallFont);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() { //myOLED.print formats with (string, text_placement, pixel_location)
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// Test if the button is being pressed
if (buttonState == HIGH) {
myOLED.clrScr();
myOLED.update();
oldButtonState = buttonState;
if (screenNumber != 2) {
++screenNumber;
}
else {
screenNumber = 0;
}
//delay a little to avoid bouncing
delay(200);
}
//Test for the screenNumber variable and change to the
//according screen
if (screenNumber == 0) {
myOLED.print("TIME", CENTER, 16);
myOLED.update();
}
else if (screenNumber == 1) {
myOLED.print("TEMPERATURE", CENTER, 16);
myOLED.update();
}
else if (screenNumber == 2) {
myOLED.print("DIRECTION", CENTER, 16);
myOLED.update();
}
else {
myOLED.print("ERROR", CENTER, 16);
myOLED.update();
}
}