How to get display to display fan speed

I am new to Arduino and programming through Arduino. For my project, I am using a fan to measure wind speed. However, the display for the project does not display anything. I have already tested to see if it works (and it does) with a sample code from adafruit. I am using arduino nano and an adafruit 0.96 inch display (Monochrome 0.96 128x64 OLED Graphic Display - STEMMA QT : ID 326 : $17.50 : Adafruit Industries, Unique & fun DIY electronics and kits). My code currently is:

#include "TimerOne.h" //Adds timekeeping for inturrupt
#include <Adafruit_NeoPixel.h>  //Neopixel controls
#include "PinChangeInterrupt.h" //adds more inturrupt pins
#include <Wire.h> //i2c 
#include <Adafruit_GFX.h> //Graphics for oled
#include <Adafruit_SSD1306.h> //Oled driver

//Fonts
#include <Fonts/FreeSansBold18pt7b.h>
#include <Fonts/FreeSans9pt7b.h>

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(4, 6, NEO_GRB + NEO_KHZ800); //pixels,pin,...
Adafruit_SSD1306 display(128, 64, &Wire, -1); //Width, Height, Comm, Reset

//USER CHANGES ----------------------
bool CALABRATE = false; //When made true more information is sent to serial monitor
float conversionMultiplier = 0.09;  //Number used to convert from ticks/sec to mph
bool mph = true; //Used when choosing starting mode between mph and m/s
//-----------------------------------

//declare colors to use

#define pinTog 8  //Button Mode1
#define pinUni 9  //Button Mode2
#define pinRec 3  //Record Inturrupt pin
#define interruptPin  2 //Fan Pulse inturrupt pin

#define brightness 255 //Neopixel standard brightness
#define timeInterval 1000000  //1,000,000 = 1second
#define clearTime 1000
int clearTarget;

bool y;
bool action = false;  //Used for standby loop
bool recording = false; //Tells program to record
bool recTogg = false; //Tell program if toggle recording is on
bool recHold = false; //Tells program if recording butting is being 'pressed'

int cycle;
int rev;
int ticks;
int totRev;
int totTicks;
int dispTicks;

float convertedSpeed;
float speedAvg;
float speedHigh;
float speedLow;
float speedPeriod;
float speedTotal;

static const unsigned char PROGMEM rim_bmp[] = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFC, 0x0F, 0xE0, 0x60, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFC, 0x0F, 0xE0, 0x70, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFC, 0x0F, 0xE0, 0x78, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0xFC, 0x0F, 0xE0, 0x7C, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFC, 0x0F, 0xE0, 0x7E, 0x00, 0x00, 0x00, 0x1F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x03, 0xFF, 0xFF, 0xFC, 0x0F, 0xE0, 0x7F, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0xFC, 0x0F, 0xE0, 0x7F, 0x80, 0x00, 0x00, 0x7F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x0F, 0xFF, 0xF0, 0x00, 0x0F, 0xE0, 0x7F, 0xC0, 0x00, 0x00, 0xFF, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x1F, 0xFE, 0x00, 0x00, 0x0F, 0xE0, 0x7F, 0xE0, 0x00, 0x01, 0xFF, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x3F, 0xF8, 0x00, 0x00, 0x0F, 0xE0, 0x7F, 0xF0, 0x00, 0x03, 0xFF, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x7F, 0xF0, 0x00, 0x00, 0x0F, 0xE0, 0x7F, 0xF8, 0x00, 0x07, 0xFF, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x7F, 0xC0, 0x00, 0x00, 0x0F, 0xE0, 0x3F, 0xFC, 0x00, 0x0F, 0xFF, 0x80, 0x00,
  0x00, 0x00, 0x00, 0xFF, 0x80, 0x00, 0x00, 0x0F, 0xE0, 0x1F, 0xFE, 0x00, 0x1F, 0xFF, 0x80, 0x00,
  0x00, 0x00, 0x00, 0xFF, 0x80, 0x00, 0x00, 0x0F, 0xE0, 0x0F, 0xFF, 0x00, 0x3F, 0xFF, 0x80, 0x00,
  0x00, 0x00, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x07, 0xFF, 0x80, 0x7F, 0xFF, 0x80, 0x00,
  0x00, 0x00, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x03, 0xFF, 0xC0, 0xFF, 0xFF, 0x80, 0x00,
  0x00, 0x00, 0x01, 0xFE, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x01, 0xFF, 0xE1, 0xFF, 0xFF, 0x80, 0x00,
  0x00, 0x00, 0x01, 0xFE, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0xFF, 0xF3, 0xFF, 0xFF, 0x80, 0x00,
  0x00, 0x00, 0x01, 0xFE, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x7F, 0xFF, 0xFF, 0xFF, 0x80, 0x00,
  0x00, 0x00, 0x01, 0xFE, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x3F, 0xFF, 0xFF, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x01, 0xFE, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x1F, 0xFF, 0xFE, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x01, 0xFE, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x0F, 0xFF, 0xFC, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x01, 0xFE, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x07, 0xFF, 0xF8, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x01, 0xFE, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x03, 0xFF, 0xF0, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x01, 0xFF, 0xE0, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0xFF, 0x80, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0xFF, 0xC0, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x7F, 0xC0, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x7F, 0x80, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x7F, 0xE0, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x3F, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x3F, 0xFC, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x1E, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x1F, 0xFF, 0x80, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x0C, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xFC, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0xFC, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x03, 0xFF, 0xFF, 0xFC, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xF8, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xF0, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xE0, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xC0, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x80, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x03, 0xFE, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x07, 0xFC, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x0F, 0xF8, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x1F, 0xF0, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x3F, 0xE0, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x7F, 0xC0, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x00, 0xFF, 0x80, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x01, 0xFF, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x03, 0xFE, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x07, 0xFC, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x0F, 0xF8, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x1F, 0xF0, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x3F, 0xE0, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x7F, 0xC0, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0xFF, 0x80, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x03, 0xFE, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x07, 0xFC, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x0F, 0xF8, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x1F, 0xF0, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x3F, 0xE0, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x3F, 0xC0, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

void setup() {
  Serial.begin(9600);
  Serial.println("Hello Liam");

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  //Start OLED Display
  display.setRotation(2); //Flip Display 180
  display.clearDisplay(); //Clear Display
  display.drawBitmap(0, 0, rim_bmp, 128, 64, 1);  //Draw Logo
  display.display();  //Display Image
  delay(3000);  //Pause With Logo for 3 Seconds

  pinMode(interruptPin, INPUT_PULLUP);  //Fan Data Pin
  attachInterrupt(digitalPinToInterrupt(pinRec), intRecord, CHANGE);  //Inturrupt to start recording
  Serial.println("You're looking well today.");
  attachPinChangeInterrupt(0, toggle, RISING);  //Mode Inturrupt
  attachPinChangeInterrupt(1, units, RISING);   //Mode Inturrupt
  Serial.println();
}

void loop() {
  if (action == false) {
    display.clearDisplay();
    display.display();
  } else if (recording == true) {
    record();
  }
}

void intRecord() {  //interrupt pin to activate recording

  action = true;  //Turn Off Standby Mode

  if (recording != true) {  //If Not Already Recording
    Serial.println("Recording started");
    recording = true; //Start Recording Fan

    if (recTogg == true) {  //If Toggle Mode is on
      recHold = true;   //Keep Record Button Pressed Through Program
    }

    cycle = -1; //Set Cycle < 0 to allow minigate error
    rev = 0;  //Reset Revolutions Per Period
    totRev = 0; //Reset Total Revolutions
    totTicks = 0; //Reset Total Ticks
    speedAvg = 0;
    speedHigh = 0;
    speedLow = 100;
    speedPeriod = 0;
    speedTotal = 0;


    detachPinChangeInterrupt(0);  //Detach Mode Inturrupt
    detachPinChangeInterrupt(1);   //Detach Mode Inturrupt

    Timer1.initialize(timeInterval);  //Record Period Interval => 1,000,000 = 1second
    Timer1.attachInterrupt(timecycle);  //Start Time Interrupt - Direct to void Timecycle each Period
    Timer1.restart();
    attachInterrupt(digitalPinToInterrupt(interruptPin), pulse, CHANGE);  //Start Fan Inturrupt - Direct to void pulse each tick
  } else if (recording == true && recTogg == true && recHold == true && digitalRead(pinRec) == HIGH) {  //If Record Toggle is on and Button is pressed a second time...
    recHold = false;
    //recEnd(); //End Recording Sequence
  }
}

void record() { //what happens while recording {

  oledAction(speedPeriod, cycle, totRev / cycle);

  if (digitalRead(pinRec) == HIGH || recHold == true) {
  } else {
    recEnd(); //End Recording Sequence
  }
}

void recEnd() {
  detachInterrupt(digitalPinToInterrupt(interruptPin));
  Timer1.stop();
  detachInterrupt(digitalPinToInterrupt(pinRec));

  Serial.println("Recording ended");

  display.clearDisplay();
  delay (200);
  display.display();
  delay (200);
  display.setCursor(0, 13);
  delay (10);
  speedAvg = speedTotal / (cycle - 1);
  display.print("MEAN: ");
  display.println(speedAvg);
  delay (10);
  display.setCursor(0, 32);
  display.print("HIGH: ");
  display.print(speedHigh);
  delay (10);
  display.setCursor(0, 51);
  display.print("LOW: ");
  display.print(speedLow);
  delay (10);
  display.setCursor(94, 60);
  if (mph == true) {
    display.print("mph");
  } else {
    display.print("m/s");
  }
  display.display();

  delay(1000);

  Serial.print("Average Speed: ");
  Serial.println(speedAvg);
  speedAvg = 0;
  Serial.print("Highest Speed: ");
  Serial.println(speedHigh);
  Serial.print("Lowest Speed: ");
  Serial.println(speedLow);

  while (digitalRead(pinTog) == LOW && digitalRead(pinUni) == LOW) {} //Wait for either mode button to be pressed
  lineWipe(5);

  recording = false;
  recHold = false;
  action = false; //Begin Standby Loop

  attachInterrupt(digitalPinToInterrupt(pinRec), intRecord, RISING);  //Inturrupt to start recording
  attachPinChangeInterrupt(0, toggle, RISING);  //Mode Inturrupt
  attachPinChangeInterrupt(1, units, RISING);   //Mode Inturrupt
}

void oledAction(int num, int cyc, int avg) {
  display.clearDisplay();
  display.setTextColor(WHITE);

  //Main Speed
  if (num < 10) {
    display.setFont(&FreeSansBold18pt7b);
    display.setCursor(46, 48);
    display.setTextSize(2);
    display.println(num);
  } else if ((num >= 10) && (num < 100)) {
    //Serial.println("10");
    display.setFont(&FreeSansBold18pt7b);
    display.setCursor(26, 48);
    display.setTextSize(2);
    display.println(num);
  } else if (num >= 100) {
    //Serial.println("100");
    display.setFont(&FreeSansBold18pt7b);
    display.setCursor(35, 36); //6 to center x2 font
    display.setTextSize(1);
    display.println(num);
  } else {
    //Lightspeed
  }

  //Set Units
  display.setFont(&FreeSans9pt7b);
  display.setCursor(94, 60);
  display.setTextSize(1);
  if (mph == true) {
    display.println("mph");
  } else {
    display.println("m/s");
  }

  //Cycle count
  if (cyc < 10) {
    display.setCursor(118, 12);
    display.println(cyc);
  } else if ((cyc >= 10) && (cyc < 100)) {
    display.setCursor(108, 12);
    display.println(cyc);
  } else if (cyc >= 100) {
    display.setCursor(118, 12);
    display.println("+");
  }

  //Display If Toggle Mode Is On
  if (recTogg == true) {
    display.setCursor(0, 6);
    display.println("+");
  }

  //display.invertDisplay(true);
  delay(10);
  display.display();
}

void timecycle() { //Interrupt Triggers After Each Time Interval
  Serial.println("TIME");
  detachInterrupt(digitalPinToInterrupt(interruptPin)); //Temporarily Disable Inturrupt

  if (cycle > 0) {  //Cycle Set < 0 to Decrease Error

    if (CALABRATE == true) {  //Use The Following Serial Data Output To Calibrate Speed Conversion Number
      Serial.println();

      Serial.print("Cycle: ");
      Serial.println(cycle);  //How Many Recordings Have Occured During This Recording

      Serial.print("Spins per second: ");
      Serial.println(rev);  //Complete Revolutions Occured During Period

      Serial.print("Ticks per second: ");
      Serial.println(ticks);  //Number Of Ticks Recordrd During Period
    }

    totRev += rev;  //Add This Period's Revolutions to Total Revolutions
    totTicks += ticks;  //Add This Period's Ticks to Total Ticks

    dispTicks = ticks;  //For OLED Display

    speedPeriod = ticks * conversionMultiplier;
    if (mph == false) {
      speedPeriod = speedPeriod * 0.44704; //If Mode Set To m/s, Convert To m/s
    }
    if (speedPeriod > speedHigh) {
      speedHigh = speedPeriod;
    }
    //if (cycle == 1) speedLow = speedPeriod;
    if (speedPeriod < speedLow) {
      speedLow = speedPeriod;
    }
    speedTotal = speedTotal + speedPeriod;
    //speedAvg = speedTotal / cycle;

    //Serial.println(speedPeriod);
    //Serial.println(speedAvg);
    //Serial.println(speedHigh);
    //Serial.println(speedLow);
  }
  rev = 0;  //Reset Period Revolutions
  ticks = 0;  //Reset Period Ticks
  cycle++;  //Add One For Next Cycle

  attachInterrupt(digitalPinToInterrupt(interruptPin), pulse, CHANGE);  //Enable Inturrupt
}

void pulse() {  //interrupt pin connected to fan pulse

  ticks++;  //Add +1 Every Time Inturrupt Is Triggered

  if (ticks % 4 == 0) { //If One Revolution Has Occured...
    rev++;  //Add +1 To Revolutions
  }
}

void units() {  //interrupt pin to change between m/s and mph
  Serial.println("Units");
  int buttonState = digitalRead(pinUni);
  for (int i = 1; i > 0; i++) {
    if (buttonState != HIGH) break;
    buttonState = digitalRead(pinUni);
    Serial.println(i);
    delay(100);
    if (i >= 200) {
      Serial.println("UNITS CHANGE");


      mph = !mph;
      break;
    }
  }
  display.clearDisplay();
  display.setTextSize(1);
  display.setFont(&FreeSans9pt7b);
  display.setTextColor(WHITE);
  display.setCursor(20, 36);
  display.print("Units: ");
  if (mph == false) {
    display.print("m/s");
  } else {
    display.print("mph");
  }
  //delay(100);
  if (y) {
    display.display();
    delay(500);
  }
}

void toggle() { //interrupt pin to change through the recording modes

  Serial.println("Toggle");
  int buttonState = digitalRead(pinTog);

  for (int i = 1; i > 0; i++) {
    if (buttonState != HIGH) break;
    buttonState = digitalRead(pinTog);
    Serial.println(i);
    delay(100);
    if (i >= 200) {
      Serial.println("MODE CHANGE");

      recTogg = !recTogg;
      attachInterrupt(digitalPinToInterrupt(pinRec), intRecord, RISING);
      break;
    }
  }
  display.clearDisplay();
  display.setTextSize(1);
  display.setFont(&FreeSans9pt7b);
  display.setTextColor(WHITE);
  display.setCursor(15, 36);
  display.print("Toggle: ");
  if (recTogg == false) {
    display.print("OFF");
  } else {
    display.print("ON");
  }
  //delay(100);
  if (y) {
    display.display();
    delay(500);
  }
}

//Sequences ----------------------------------------------------------------------------
void stand(int bef, int aft, int itv, int del, bool reset, uint32_t color) { //Standby neopixel sequence: runs through loop when action == false
  if (!y) {
    for (int j = bef; j <= aft; j++) {
      if (action == true) break;
      //Serial.println(j);
      display.display();
      delay(del);
      j += itv;
    }
    for (int j = aft; j >= bef; j--) { //darken
      if (action == true) break;
      //Serial.println(j);
      display.display();
      delay(del);
      j -= itv;
    }
    Serial.println("standby");
  }
}

//Screen animations --------------------------------------------------------------------
void lineWipe(int thick) {
  //Serial.println("linewipe");
  for (int i = 64; i < display.width(); i += thick) {
    for (int j = 0; j < thick; j++) {
      display.drawLine((i + j), 0, (i + j), 63, SSD1306_BLACK); //(x1, y1, x2, y2, color)
      display.drawLine(128 - (i + j), 0, 128 - (i + j), 63, SSD1306_BLACK);
    }
    display.display();
    delay(1);
  }
}

Help on why the display is not showing anything and any potential fixes are greatly appreciated.

The for loop in function toggle will lock up and run 32768 times before exiting. That looks wrong.

Sorry but it helps if you post a schematic as you have wired it. I have several fans in my home, all different. Post a link to the "Technical information on the fan" so we can see what needs to be accomplished.

It is clear from your code that you do not understand the implications of using interrupts. Why are you using interrupts for buttons? How are your buttons wired? Do you have pullup or pulldown resistors on your buttons?

You have violated all of the following when using interrupts:

  • All variables shared between ISR and non-ISR code should be declared with the volatile keyword.
  • All multibyte variables shared between ISR and non-ISR code are at risk of being corrupted if reads and writes of those are not protected in the non-ISR code by disabling interrupts while reading or writing them. (applies to processors with a data bus width less that the variable width you are sharing)
  • You should not call delay() or any function which performs I/O that depends on interrupts in an ISR. In your case Serial or display functions.
  • Interrupts should be as short as possible. Usually increment a counter, set a flag, read/write a register/buffer.

Using interrupts when you don't absolutely need to makes the code difficult to debug and manage.

Actually it looks like it will exit when i >= 200; however, the point is mute. This code is in an interrupt!!! delay() and Serial functions should not be called! Even if it did work it could delay up to 20 seconds...in an interrupt. As I stated earlier, complete misunderstanding/misguidance of the purpose of interrupts.

  for (int i = 1; i > 0; i++) {
    if (buttonState != HIGH) break;
    buttonState = digitalRead(pinTog);
    Serial.println(i);
    delay(100);
    if (i >= 200) {
      Serial.println("MODE CHANGE");

      recTogg = !recTogg;
      attachInterrupt(digitalPinToInterrupt(pinRec), intRecord, RISING);
      break;
    }
  }
1 Like

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