MEGA2560 outputting incorrect voltages

Hi,

So I'm trying to make an Arduino calculator and I'm breaking up the code into small sections to get through it.
This part of code is meant to make the number 9 output onto my first seven segment display (common cathode) when the input button (push to make from +5V) is held down. I'm planning to also use interrupts for each input but originally I'm going to start from the bare minimum to reduce the amount of things that can go wrong... Although it hasn't worked because I'm on here.

My problem is, when I turn the arduino on, it outputs the number 9 on the seven segment display whilst the button is low.

const int NoNine = 28;               //Input Number Nine
const int SSg = 45;                  //Seven Segment input g
const int SSf = 46;                  //Seven Segment input f
const int SSe = 47;                  //Seven Segment input e
const int SSd = 48;                  //Seven Segment input d
const int SSc = 50;                  //Seven Segment input c
const int SSb = 52;                  //Seven Segment input b
const int SSa = 53;                  //Seven Segment input a
const int SSDF = 49;                 //Seven Segment Driver F

volatile int NoNineState = LOW;               //Input Number Nine
int SSgState = LOW;                  //Seven Segment input g
int SSfState = LOW;                 //Seven Segment input f
int SSeState = LOW;                 //Seven Segment input e
int SSdState = LOW;                 //Seven Segment input d
int SScState = LOW;                 //Seven Segment input c
int SSbState = LOW;                 //Seven Segment input b
int SSaState = LOW;                 //Seven Segment input a
int SSDFState = LOW;                       //Seven Segment Driver F

int h = 0;
int i = 1;

void setup() {
  // put your setup code here, to run once:
  pinMode(NoNine, INPUT);
  pinMode(SSg, OUTPUT);
  pinMode(SSf, OUTPUT);
  pinMode(SSe, OUTPUT);
  pinMode(SSd, OUTPUT);
  pinMode(SSc, OUTPUT);
  pinMode(SSb, OUTPUT);
  pinMode(SSa, OUTPUT);
  pinMode(SSDF, OUTPUT);
}

void loop() {
  if (digitalRead(NoNine) == HIGH)
  {
    IntNoNine();
  }
  else
  {
    h = 0;
  }
  DisplayFirst( h, i);
  delay(5);
}

void DisplayFirst (int h, int i)
{
  if (h = 9)
  {
    displayNine();
  }
    if (h = 0)
  {
    displayNULL();
  }
    if (i = 1)
  {
    driveF();
  }  
}

void IntNoNine()
{
  h = 9;
  loop();   
}



void displayNine()
{         //9
  digitalWrite(SSg, HIGH);
  digitalWrite(SSf, HIGH);
  digitalWrite(SSe, LOW);
  digitalWrite(SSd, LOW);
  digitalWrite(SSc, HIGH);
  digitalWrite(SSb, HIGH);
  digitalWrite(SSa, HIGH);
}
void driveF()
{          //SSDF
  digitalWrite(SSDF, HIGH);
}
void displayNULL()
{         //None Output                                    (h = 0)
  digitalWrite(SSg, LOW);
  digitalWrite(SSf, LOW);
  digitalWrite(SSe, LOW);
  digitalWrite(SSd, LOW);
  digitalWrite(SSc, LOW);
  digitalWrite(SSb, LOW);
  digitalWrite(SSa, LOW);
}

button (push to make from +5V) is held down.

Is there a pull down resistor from the input to ground?

void IntNoNine()
{
  h = 9;
  loop();   
}

You are calling the loop() function recursively. Sooner or later (usually sooner) your code will mysteriously crash.

    IntNoNine();

All this function does (the useful bit) is set h to 9. Get rid of the function altogether and just set h to 9 here.

To add to what @groundfungus asked, if there’s no resistor on the NoNine pin, it is floating and can read high or low as it sees fit. You need a resistor. I would suggest that you set the internal pullup resistor and set h to 9 when the button is LOW.
You’ll also have to debounce the button.

Pete

  if (h = 9)
  {

there's an 'oops' here, check out your comparison operators.

groundfungus:
Is there a pull down resistor from the input to ground?

Yes there is a resistor between ground and the button. It is wired up correctly (take my word if I'm not explaining enough) and there is a constant zero volts on the input until the button is pushed.

el_supremo:
You are calling the loop() function recursively. Sooner or later (usually sooner) your code will mysteriously crash.

This function was me peeling back the code, I understand what you’re saying but I was going to use this function as the ISR for the input’s interrupt. The button is also wired correctly with a resistor between it and the zero volt rail which makes it output zero volts until it is pressed.

el_supremo:
You’ll also have to debounce the button.

I’m planning to do this but as I said I was just stripping back the code to the bare essentials to make fault finding easier.

Thanks for replying either way!