Hardware interrupt on pin change logic help needed

I don't know why I struggle with this.

I have an analog sensor, for ease of use, that reads from 0-1023. Above 512 I am writing digitalPin(2) high and below 512 I am writing digitalPin(2) low. I have an ISR attached to digitalPin(2) on change. I am struggling with the logic to get the information I want.

I want the time interval between High and Low, and Low and High, then I want the total time between High and High. This is easy to do with pulseIn, however the hardware I am trying to do this with is already set and I don't think I can write a pin high and read it at the same time.

I'm confused. Are you saying that you don't think you can do something like this?

   digitalWrite(pin, HIGH);
   if( digitalRead(pin) == HIGH ) {
      Serial.println("The pin state is HIGH.");
   }

Because you absolutely can.

This seems contorted :thinking:

  • If you are making pin 2 HIGH/LOW you can set a variable(s) to either millis( ) or micros( ).

  • Use the values to calculate the times.

  • Pin 2 is being used as an output and you want to use input pin interrupts ?

  • What is the need for interrupts ?

2 Likes

But can I write pin 2 high, then do pulse in on pin 2?

It is contorted because I am trying to make something I already have give this info.

It is much better to use different pins for input and output.

Can I write and read a pin is a different kettle of fish than can I do input on an output pin. I expect the answer to the latter is no.

But yes, I am struggling with the logic on the times. I set the interrupt to output the times, but this is for the pin change and I am having difficulty with the logic of when pin 2 is high and interrupt happens record time as pin change to low, else when pin 2 is low and interrupt happens record change as pin 2 going to high. My values are not ending up quite right.

I would like the asymmetry between the High and Low




//for Assymetry
unsigned long HighMicros;
unsigned long LowMicros;
float ASSYMN;
float ASSYMS;
unsigned long Htime;
unsigned long Ltime;
unsigned long Ttime;
volatile unsigned long AsymisrMicros;
volatile bool AsymnewIsrMicros;





void setup() {
  Serial.begin(9600);
   if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    }
  attachInterrupt(digitalPinToInterrupt(2), AsymISR, CHANGE);
 

} // End Setup




void loop() {
getIsrData();




  display.display();
  
 
 
 
 Serial.print(Htime);
 Serial.println();
 Serial.print(Ltime);
 Serial.println();
 Serial.print(Ttime);

 /*
 if (digitalRead(2) == HIGH) {
   Serial.print("True");
 } else {
   Serial.print("False");
 }
 */

 



 
} // end loop

// Assymetry Data
void getIsrData() {
    if (AsymnewIsrMicros == true && digitalPin(2) == HIGH {
        HighMicros = AsymisrMicros; // Record start time for HIGH
    } else if (AsymnewIsrMicros == true && digitalPin(2)) == LOW {
     LowMicros = AsymisrMicros; // Record start time for LOW
    }
        noInterrupts();
            AsymnewIsrMicros = false;
            interrupts();
Htime = LowMicros - HighMicros;
Ltime = HighMicros - LowMicros;
Ttime = (Htime + Ltime);
ASSYMN = Ltime/Htime; 
ASSYMS = Htime/Ltime; 
} // End getIsrData


 // AsymISR
void AsymISR() {
    AsymisrMicros = micros();
    AsymnewIsrMicros = true;
    
} // End ISR


Ttime ends up cancelling out due to math...

Yes, that should be digitalRead sorry. I was converting my code to something I could post. The pin is being written high and low in my actual code based on the value of the sensor, that part shouldn't matter and does work.

Like I said, I am struggling with the logic of the times. The "state machine" style code you are referring to. I get the code can't interpret where I am on the wave. That is where I need help.

Please try to explain, in clear English, what you want to do. Your most recent post is unintelligible.

Pin 2 in my code is being written high or low based on the value of a sensor.

I would like to to measure the asymmetry between high and low.

This is not the ideal way to do this, I am trying to add this feature to hardware I have already built.

I want the time the pin is high and the time the pin is low so I can compare the time it is high to the time it is high + low. Ultimately this will lead to a percentage.

I posted interrupt, I meant interpret.

  • Still not sure what you are asking for.

  • This should give you some ideas:

const byte analogSensor       = A0;
int hysteresis                = 5;
int lastValue;
bool highLowFlag              = false;

const byte outputPin          = 8;

unsigned long wentHigh;
unsigned long wentLow;


//***********************************************************************
void setup()
{
  Serial.begin(115200);

  digitalWrite(outputPin, LOW);
  pinMode(outputPin, OUTPUT);

} //END of   setup()

//***********************************************************************
void loop()
{
  int sensorValue = analogRead(analogSensor);
  int change = abs(lastValue - sensorValue);

  if (change > hysteresis)
  {
    lastValue = sensorValue;

    if (highLowFlag == false && sensorValue >= 512)
    {
      highLowFlag = true;

      digitalWrite(outputPin, HIGH);

      Serial.print("LOW to HIGH = ");
      Serial.println(millis() - wentLow);

      Serial.print("HIGH to HIGH = ");
      Serial.println(millis() - wentHigh);

      wentHigh = millis();
    }

    if (highLowFlag == true && sensorValue < 512 - hysteresis)
    {
      highLowFlag = false;

      digitalWrite(outputPin, LOW);

      Serial.print("HIGH to LOW = ");
      Serial.println(millis() - wentHigh);

      wentLow = millis();
    }
  }

} //END of    loop()

//***********************************************************************

This device measures the gauss of a bldc 540 size rotor. I have a public github page that has the pcb gerbers, bom, stl files to print a case, and the last code I uploaded. I have made some changes since then. I am coming out with a V2, and I want to add the feature of rotor asymmetry. All that said, I do sell these to a very small market and wasn't going to post my new code.

/* Rotor Master v1.1
A WHM Racing product
written by Andrew Sarratore
Date: 7/31/2023

v1.2
added logo to the setup and loop
Date: 9/10/2023

v1.3
Changed from the single read to an average of 30
Date: 9/17/2023

v1.4
Adding Asymmetry to the reading
Date: 11/16/2023
*/



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

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define SELPIN 10 //Selection Pin 
#define DATAOUT 11//MOSI 
#define DATAIN  12//MISO 
#define SPICLOCK  13//Clock 



// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// Edit the below values with actual values
float VCC = 5.000; // Arduino Voltage
float QOV1 = 2.500;  // Quiescent Output Sensor1
float QOV2 = 2.500;  // Quiescent Output Sensor2
float QOV3 = 2.500;  // Quiescent Output Sensor3
float M1 = 1.000; // Multiplier Sen
int Offset1 = 2048; // Set raw reading to 0
int Offset2 = 2048; // Set raw reading to 0
int Offset3 = 2048; // Set raw reading to 0
float Sensitivity = 0.0013;
int DEL=0; // Set this to 0 with final upload
float divider = (4095 / VCC); // Compensate for Voltage difference of 5v
int readvalue1; //Raw read from ADC1
int readvalue2; //Raw read from ADC2
int readvalue3; //Raw read from ADC3
int Zero1; // Zero the reading for calculations, allows for +/-
int Zero2; // Zero the reading for calculations, allows for +/-
int Zero3; // Zero the reading for calculations, allows for +/-
int Gauss1; //Calculated Gauss
int Gauss2; //Calculated Gauss
int Gauss3; //Calculated Gauss
int HighGauss1=0; //Variable for Max + Value
int HighGauss2=0; //Variable for Max + Value
int HighGauss3=0; //Variable for Max + Value
int LowGauss1=0; //Variable for Max - Value
int LowGauss2=0; //Variable for Max - Value
int LowGauss3=0; //Variable for Max - Value
float Voltage1; // Voltage of Zero
float Voltage2; // Voltage of Zero
float Voltage3; // Voltage of Zero
float G1; // Gauss before Multiplier
float G2; // Gauss before Multiplier
float G3; // Gauss before Multiplier
float OffsetV1;
float OffsetV2;
float OffsetV3;
int i = 0;
int j = 0;
int k = 0;
long int avg1 = 0;
long int avg2 = 0;
long int avg3 = 0;
long int ADC1 = 0;
long int ADC2 = 0;
long int ADC3 = 0;
long int AverageADC1 = 0;
long int AverageADC2 = 0;
long int AverageADC3 = 0;
//for Assymetry
unsigned long HighMicros;
unsigned long prevHighMicros;
unsigned long LowMicros;
unsigned long prevLowMicros;
float ASSYMN;
float ASSYMS;
unsigned long Htime;
unsigned long Ltime;
unsigned long Ttime;
volatile unsigned long AsymisrMicros;
volatile bool AsymnewIsrMicros;


//Bitmap Logos

const unsigned char LogoIcon[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x23, 0x20, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x00, 0x23, 0x60, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x00, 0x30, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf0, 0x00, 0x1f, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xf8, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xfe, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xfe, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x40, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x78, 0x0f, 0x00, 0xf2, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x0f, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xf0, 0x07, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xe0, 0x07, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xf0, 0x07, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xf0, 0x07, 0xff, 0xf2, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xe0, 0x07, 0xff, 0xf2, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xe0, 0x03, 0xff, 0xf2, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xe0, 0x03, 0xff, 0xf2, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xe0, 0x03, 0xff, 0xf2, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xe0, 0x03, 0xff, 0xf2, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xe0, 0x07, 0xff, 0xf2, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc3, 0xe0, 0x07, 0xe3, 0xf2, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x03, 0xf0, 0x07, 0xe0, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x07, 0xe0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0x0f, 0xe0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0x0f, 0xf0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x1f, 0xf0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x7f, 0xf0, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf8, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
/*
const unsigned char Logotxt [] PROGMEM = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x0b, 0x40, 0x1d, 0xc0, 0x3b, 0x00, 0x00, 0x7c, 0x00, 0x70, 0x01, 0xc0, 0x38, 0x07, 0x60, 0x07, 
  0x0b, 0xc0, 0x0d, 0x80, 0x1b, 0x00, 0x00, 0x3c, 0x00, 0x70, 0x03, 0x80, 0x18, 0x03, 0x60, 0x0f, 
  0x0f, 0xc0, 0x1f, 0x80, 0x1f, 0x00, 0x00, 0x2c, 0x00, 0xf0, 0x02, 0x00, 0x10, 0x03, 0xc0, 0x0f, 
  0x6f, 0x80, 0xff, 0x81, 0xfe, 0x00, 0x03, 0xbc, 0x0f, 0xf0, 0x3e, 0x01, 0xf0, 0x3b, 0xc0, 0x6b, 
  0x6f, 0x80, 0xff, 0x80, 0xd6, 0x00, 0x01, 0xe8, 0x07, 0xf0, 0x1f, 0x80, 0xf0, 0x1a, 0xc0, 0x6f, 
  0x0f, 0x80, 0x15, 0x80, 0x76, 0x00, 0x00, 0xec, 0x03, 0xb0, 0x07, 0x80, 0x70, 0x0e, 0xc0, 0x0e, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
*/


void setup() {
  Serial.begin(9600);
   if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    }
  attachInterrupt(digitalPinToInterrupt(2), AsymISR, CHANGE);
  delay(1000);
  display.clearDisplay();
  display.drawBitmap(0, 0, LogoIcon, 128, 64, WHITE);
  display.display(); 
  pinMode(SELPIN, OUTPUT); 
  pinMode(DATAOUT, OUTPUT); 
  pinMode(DATAIN, INPUT); 
  pinMode(SPICLOCK, OUTPUT); 
  pinMode(2, OUTPUT);
  digitalWrite(SELPIN,HIGH); 
  digitalWrite(DATAOUT,LOW); 
  digitalWrite(SPICLOCK,LOW); 
  delay(500);

} // End Setup


int read_adc(int channel){
  int adcvalue = 0;
  byte commandbits = B11000000; //command bits - start, mode, chn (3), dont care (3)

  //allow channel selection
  commandbits|=((channel-1)<<3);

  digitalWrite(SELPIN,LOW); //Select adc
  // setup bits to be written
  for (int i=7; i>=3; i--){
    digitalWrite(DATAOUT,commandbits&1<<i);
    //cycle clock
    digitalWrite(SPICLOCK,HIGH);
    digitalWrite(SPICLOCK,LOW);    
  }

  digitalWrite(SPICLOCK,HIGH);    //ignores 2 null bits
  digitalWrite(SPICLOCK,LOW);
  digitalWrite(SPICLOCK,HIGH);  
  digitalWrite(SPICLOCK,LOW);

  //read bits from adc
  for (int i=11; i>=0; i--){
    adcvalue+=digitalRead(DATAIN)<<i;
    //cycle clock
    digitalWrite(SPICLOCK,HIGH);
    digitalWrite(SPICLOCK,LOW);
  }
  digitalWrite(SELPIN, HIGH); //turn off device
  return adcvalue;
}


void loop() {
//readvalue1 = read_adc(1); 
getIsrData();
while(i<30) {
  ADC1 = read_adc(1);
  avg1 += ADC1;
  i++;
}
AverageADC1 = avg1/30;
avg1=0;
i=0;
//readvalue2 = read_adc(2);
while(j<30) {
  ADC2 = read_adc(2);
  avg2 += ADC2;
  j++;
}
AverageADC2 = avg2/30;
avg2=0;
j=0;
//readvalue3 = read_adc(3); 
while(k<30) {
  ADC3 = read_adc(3);
  avg3 += ADC3;
  k++;
}
AverageADC3 = avg3/30;
avg3=0;
k=0;

OffsetV1 = (Offset1 - (QOV1 * divider)) / divider; 
OffsetV2 = (Offset2 - (QOV2 * divider)) / divider;
OffsetV3 = (Offset3 - (QOV3 * divider)) / divider;
Voltage1 = (AverageADC1) / divider;
Voltage2 = (AverageADC2) / divider;
Voltage3 = (AverageADC3) / divider;
Zero1 = AverageADC1 - Offset1;
Zero2 = AverageADC2 - Offset2;
Zero3 = AverageADC3 - Offset3;
G1 = ((Voltage1 - OffsetV1)-QOV1) / Sensitivity;
G2 = ((Voltage2 - OffsetV2)-QOV2) / Sensitivity;
G3 = ((Voltage3 - OffsetV3)-QOV3) / Sensitivity;
Gauss1 = G1 * M1;
Gauss2 = G2 * M1;
Gauss3 = G3 * M1;
if (Gauss1 > HighGauss1) HighGauss1 = Gauss1;
if (Gauss2 > HighGauss2) HighGauss2 = Gauss2;
if (Gauss3 > HighGauss3) HighGauss3 = Gauss3;
if (Gauss1 < LowGauss1) LowGauss1 = Gauss1;
if (Gauss2 < LowGauss2) LowGauss2 = Gauss2;
if (Gauss3 < LowGauss3) LowGauss3 = Gauss3;

if (Gauss2 >= 0) {
  digitalWrite(2, HIGH);
}
  else
  {
    digitalWrite(2, LOW);
  }


  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.print(ASSYMN);
 // display.print("/");
 // display.print(ASSYMS);
  //display.drawBitmap(0, 0, Logotxt, 128, 15, WHITE);
  display.setTextSize(2);
  display.setCursor(0,16);
  if ((Gauss1 <= 10) && (Gauss1 >= -10)) {
    display.println("0");
  } 
    else
    {
      display.print(Gauss1);
    }

  display.setCursor(64,16);
  if (Gauss1 >= 0) 
   {
     display.print("+");
     display.print(HighGauss1);
   }
     else
     {
       display.print(LowGauss1);
     }

  display.setCursor(0,32);
  if ((Gauss2 <= 10) && (Gauss2 >= -10)) {
  display.println("0");
  } 
    else
    {
      display.print(Gauss2);
    }

  display.setCursor(64,32);
  if (Gauss2 >= 0) 
    {
      display.print("+");
      display.print(HighGauss2);
    }
     else
     {
       display.print(LowGauss2);
     }

  display.setCursor(0,48);
  if ((Gauss3 <= 10) && (Gauss3 >= -10)) {
    display.println("0");
  } 
    else
    {
      display.print(Gauss3);
    }

  display.setCursor(64,48);
  if (Gauss3 >= 0) 
    {
      display.print("+");
      display.print(HighGauss3);
    }
      else
      {
        display.print(LowGauss3);
      }

  display.display();
  
 
 
 Serial.print(AverageADC1); 
 Serial.print(" RV1 ");
 Serial.println();
 Serial.print(AverageADC2); 
 Serial.print(" RV2 ");
 Serial.println(" "); 
 Serial.print(AverageADC3); 
 Serial.print(" RV3 ");
 Serial.println(" "); 
 Serial.print(Htime);
 Serial.println();
 Serial.print(Ltime);
 Serial.println();
 Serial.print(Ttime);

 /*
 if (digitalRead(2) == HIGH) {
   Serial.print("True");
 } else {
   Serial.print("False");
 }
 */

 

delay(DEL);

 
} // end loop

// Assymetry Data
void getIsrData() {
    if (AsymnewIsrMicros == true && Gauss2 >=0) {
        HighMicros = AsymisrMicros; // Record start time for HIGH
    } else if (AsymnewIsrMicros == true && Gauss2 < 0) {
     LowMicros = AsymisrMicros; // Record start time for LOW
    }
        noInterrupts();
            AsymnewIsrMicros = false;
            interrupts();
Htime = LowMicros - HighMicros;
Ltime = HighMicros - LowMicros;
Ttime = (Htime + Ltime);
ASSYMN = Ltime/Htime;
ASSYMS = Htime/Ltime;
} // End getIsrData


 // AsymISR
void AsymISR() {
    AsymisrMicros = micros();
    AsymnewIsrMicros = true;
    
} // End ISR

This I don't understand. I don't know why time confuses me so much with the programming. But you say record it right there, how? How do I call that value in my calculations? How do I update that value the next time the pin goes high or low and how do I keep the old value?

Did you look at the sketch in post #19 ?

I did.
I need a good book, tutorial, or primer to read on it. I've tried reading the Nick Gammon stuff, but that is difficult. Once I really get it, I can put it to use, but for some reason I am struggling.

Because I thought I needed an interrupt to record the time. So you are saying that setting a variable = millis() records the time when the event happens?