Results 1 to 4 of 4
  1. #1
    25+ Posting Member
    Join Date
    Apr 2012
    Location
    New Zealand
    Posts
    35
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Seeking help combining Sketchs.......

    Hi guys, sadly im back asking for help again so sorry lol......finally got all my AP 7 Seg Leds up and running but sadly each set of digits is run off 3 diff arduino cards which is such a waste of rescources and would like a lil help on combining what i have, thnx in advance!!!


    P.S b4 i go posting my 3 diff sketchs can someone tell me the correct method for displaying sketchs, i did it once b4 but for the life of me cant remember how lol ....

  2. Likes flyinjake liked this post
  3. #2
    25+ Posting Member
    Join Date
    Apr 2012
    Location
    New Zealand
    Posts
    35
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Seeking help combining Sketchs.......

    Apspd Sketch

    Code:
     
    int pinSegmentA = 22;        // Connect this pin to all 7-digit displays for the "A" segment
    int pinSegmentB = 24;        // Connect this pin to all 7-digit displays for the "B" segment
    int pinSegmentC = 26;        // Connect this pin to all 7-digit displays for the "C" segment
    int pinSegmentD = 28;        // Connect this pin to all 7-digit displays for the "D" segment
    int pinSegmentE = 30;        // Connect this pin to all 7-digit displays for the "E" segment
    int pinSegmentF = 32;        // Connect this pin to all 7-digit displays for the "F" segment
    int pinSegmentG = 34;        // Connect this pin to all 7-digit displays for the "G" segment
    
    int pinDigitHundreds = 36;   // Connect this pin to a resistor (around 100 ohms) and the other end of the resistor to 
    // the common annode pin of the 7-segment display for "Hundreds" Digit
    int pinDigitTens = 38;      // Connect this pin to a resistor (around 100 ohms) and the other end of the resistor to 
    // the common annode pin of the 7-segment display for "Tens" Digit
    int pinDigitOnes = 40;      // Connect this pin to a resistor (around 100 ohms) and the other end of the resistor to
    // the common annode pin of the 7-segment display for "Ones" Digit
    
    
    int apSpeed = 0;
    
    const boolean displayLeadingZeros = true; // This is a constant used to determine if we should be displaying leading zeros
    
    void setup() {
      // Initialize all of the output pins
      pinMode(pinSegmentA, OUTPUT);        // TOP of segment
      pinMode(pinSegmentB, OUTPUT);        // TOP RIGHT of segment
      pinMode(pinSegmentC, OUTPUT);        // BOTTOM RIGHT of segment
      pinMode(pinSegmentD, OUTPUT);        // BOTTOM of segment
      pinMode(pinSegmentE, OUTPUT);        // BOTTOM LEFT of segment
      pinMode(pinSegmentF, OUTPUT);        // TOP LEFT of segment
      pinMode(pinSegmentG, OUTPUT);        // MIDDLE of segment
      pinMode(pinDigitHundreds, OUTPUT);   // Common Annode of segment 1
      pinMode(pinDigitTens, OUTPUT);       // Common Annode of segment 2
      pinMode(pinDigitOnes, OUTPUT);       // Common Annode of segment 3
      
      // initialize the serial port and it's speed
      Serial.begin(115200);  
    }
    
    void loop() {
      // put your main code here, to run repeatedly: 
      displayValue(apSpeed);    // continously display the value on the 7-segment displays
      
      // If there is data in the serial buffer than it should be read
      if (Serial.available() > 0) {
        ReadSerialInput();
      }
    }
    
    void ReadSerialInput () {
     // This function reads the values from the serial interface
     int j1;
     j1 = Serial.read();
     
     // Check for the "autopilot apHeading"
     if (j1 == 'u') {
       delay(11);  // It seems to require a small delay before reading the next character
       apSpeed = 0;
       apSpeed = AddSerialDigit (Serial.read(), apSpeed);  // Read the first character and convert it to a digit which is attached to the integer
       apSpeed = AddSerialDigit (Serial.read(), apSpeed);  // Read the second character and convert it to a digit which is attached to the integer
       apSpeed = AddSerialDigit (Serial.read(), apSpeed);  // Read the third character and convert it to a digit which is attached to the integer
       // Serial.print("apHeading - ");
       // Serial.println(apHeading);
     }
     
    }
    
    int AddSerialDigit (int inByte, int inValue) {
      return ((inValue * 10) + CharToInteger(inByte)); 
    }
    
    int CharToInteger (int inByte) {
      // This function converts an incoming Char(byte) to an actual integer...
      
      switch (inByte) {
        case '1':
          return 1;
          break;
        case '2':
          return 2;
          break;
        case '3':
          return 3;
          break;
        case '4':
          return 4;
          break;
        case '5':
          return 5;
          break;
        case '6':
          return 6;
          break;
        case '7':
          return 7;
          break;
        case '8':
          return 8;
          break;
        case '9':
          return 9;
          break;
        default:
          return 0;
          break;
      }
    }
    
    void displayValue(int incomingValue) {
    
      boolean displayTens = false;                // This boolean is used to decide if we should show the tens digit.
      // in other word, the number may be 100 so the tens zero needs to be
      // displayed regardless of the value
    
        if ((incomingValue > 99) || (displayLeadingZeros == true)) {
        // If the value is greater than 99 than there is a hundreds digit to display
        // or we want to display a leading zero
    
        if (incomingValue > 299) {
          DisplayDigit (3, 1);                    // Display the number 3 in the hundreds place
          incomingValue = incomingValue - 300;    // subtract 300 from the value so we are leftover with the tens and ones
          displayTens = true;                     // we will need to display the tens value
        }
        else if (incomingValue > 199) {
          DisplayDigit (2, 1);                    // Display the number 2 in the hundreds place
          incomingValue = incomingValue - 200;    // subtract 200 from the value so we are leftover with the tens and ones
          displayTens = true;                     // we will need to display the tens value
        }
        else if (incomingValue > 99) {
          DisplayDigit (1, 1);                    // Display the number 1 in the hundreds place
          incomingValue = incomingValue - 100;    // subtract 300 from the value so we are leftover with the tens and ones
          displayTens = true;                     // we will need to display the tens value
        }
        else {
          DisplayDigit (0, 1);                    // Display the number 0 in the hundreds place
        }
      }
      if ((incomingValue > 9) || (displayLeadingZeros == true) || (displayTens = true)) {
        // If the value is greater than 9 than there is a hundreds digit to display
        // or we want to display a leading zero
    
        if (incomingValue > 89) {
          DisplayDigit (9, 2);                    // Display the number 9 in the tens place
          incomingValue = incomingValue - 90;    // subtract 90 from the value so we are leftover with the ones
        }
        else if (incomingValue > 79) {
          DisplayDigit (8, 2);                    // Display the number 8 in the tens place
          incomingValue = incomingValue - 80;    // subtract 80 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 69) {
          DisplayDigit (7, 2);                    // Display the number 7 in the tens place
          incomingValue = incomingValue - 70;    // subtract 70 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 59) {
          DisplayDigit (6, 2);                    // Display the number 6 in the tens place
          incomingValue = incomingValue - 60;    // subtract 60 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 49) {
          DisplayDigit (5, 2);                    // Display the number 5 in the tens place
          incomingValue = incomingValue - 50;    // subtract 50 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 39) {
          DisplayDigit (4, 2);                    // Display the number 4 in the tens place
          incomingValue = incomingValue - 40;    // subtract 40 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 29) {
          DisplayDigit (3, 2);                    // Display the number 3 in the tens place
          incomingValue = incomingValue - 30;    // subtract 30 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 19) {
          DisplayDigit (2, 2);                    // Display the number 2 in the tens place
          incomingValue = incomingValue - 20;    // subtract 20 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 9) {
          DisplayDigit (1, 2);                    // Display the number 1 in the tens place
          incomingValue = incomingValue - 10;    // subtract 10 from the value so we are leftover with the tens and ones
        }
        else {
          DisplayDigit (0, 2);                    // Display the number 0 in the tens place
        }
      }
    
      if (incomingValue > 8) {
        DisplayDigit (9, 3);                    // Display the number 9 in the ones place
      }
      else if (incomingValue > 7) {
        DisplayDigit (8, 3);                    // Display the number 8 in the ones place
      }
      else if (incomingValue > 6) {
        DisplayDigit (7, 3);                    // Display the number 7 in the ones place
      }
      else if (incomingValue > 5) {
        DisplayDigit (6, 3);                    // Display the number 6 in the ones place
      }
      else if (incomingValue > 4) {
        DisplayDigit (5, 3);                    // Display the number 5 in the ones place
      }
      else if (incomingValue > 3) {
        DisplayDigit (4, 3);                    // Display the number 4 in the ones place
      }
      else if (incomingValue > 2) {
        DisplayDigit (3, 3);                    // Display the number 3 in the ones place
      }
      else if (incomingValue > 1) {
        DisplayDigit (2, 3);                    // Display the number 2 in the ones place
      }
      else if (incomingValue > 0) {
        DisplayDigit (1, 3);                    // Display the number 1 in the ones place
      }
      else {
        DisplayDigit (0, 3);                    // Display the number 0 in the ones place
      }
    
    
    
    }
    
    
    void DisplayDigit(int DigitToDisplay, int PlaceToDisplay) {
      // This function displays a digit in a location
      // digit should be 0 through 9
      // place should be 1 through 3 (1 being hundred, 2 being tens, 3 being ones place holder)
    
      // Turn Off All Digits
      digitalWrite(pinDigitHundreds, LOW);    // turn the Hundreds Digit Off
      digitalWrite(pinDigitTens, LOW);        // turn the Tens Digit Off
      digitalWrite(pinDigitOnes, LOW);        // turn the Ones Digit Off
    
      switch (DigitToDisplay) {
      case 0: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, LOW);    // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, HIGH);   // MIDDLE
          break;
        }
      case 1: 
        {
          digitalWrite(pinSegmentA, HIGH);   // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, HIGH);   // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, HIGH);   // TOP LEFT
          digitalWrite(pinSegmentG, HIGH);   // MIDDLE
          break;
        }
      case 2: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, HIGH);   // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, LOW);    // BOTTOM LEFT
          digitalWrite(pinSegmentF, HIGH);   // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 3: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, HIGH);   // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 4: 
        {
          digitalWrite(pinSegmentA, HIGH);   // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, HIGH);   // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 5: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, HIGH);   // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 6: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, HIGH);   // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, LOW);    // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 7: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, HIGH);   // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, HIGH);   // TOP LEFT
          digitalWrite(pinSegmentG, HIGH);   // MIDDLE
          break;
        }
      case 8: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, LOW);    // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 9: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, HIGH);   // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      }
    
      switch(PlaceToDisplay) {
      case 1: 
        {
          digitalWrite(pinDigitHundreds, HIGH);    // turn the Hundreds Digit ON
          break;
        }
      case 2: 
        {
          digitalWrite(pinDigitTens, HIGH);        // turn the Tens Digit ON
          break;
        }
      case 3: 
        {
          digitalWrite(pinDigitOnes, HIGH);        // turn the Ones Digit ON
          break;
        }
      }
    
      // wait 5 milliseconds, this makes sure that the digit is shown long enough before looping
      delay(5); 
    }

  4. #3
    25+ Posting Member
    Join Date
    Apr 2012
    Location
    New Zealand
    Posts
    35
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Seeking help combining Sketchs.......

    Aphdg Sketch

    Code:
    int pinSegmentA = 2;        // Connect this pin to all 7-digit displays for the "A" segment
    int pinSegmentB = 3;        // Connect this pin to all 7-digit displays for the "B" segment
    int pinSegmentC = 4;        // Connect this pin to all 7-digit displays for the "C" segment
    int pinSegmentD = 5;        // Connect this pin to all 7-digit displays for the "D" segment
    int pinSegmentE = 6;        // Connect this pin to all 7-digit displays for the "E" segment
    int pinSegmentF = 7;        // Connect this pin to all 7-digit displays for the "F" segment
    int pinSegmentG = 8;        // Connect this pin to all 7-digit displays for the "G" segment
    
    int pinDigitHundreds = 9;   // Connect this pin to a resistor (around 100 ohms) and the other end of the resistor to 
    // the common annode pin of the 7-segment display for "Hundreds" Digit
    int pinDigitTens = 10;      // Connect this pin to a resistor (around 100 ohms) and the other end of the resistor to 
    // the common annode pin of the 7-segment display for "Tens" Digit
    int pinDigitOnes = 11;      // Connect this pin to a resistor (around 100 ohms) and the other end of the resistor to
    // the common annode pin of the 7-segment display for "Ones" Digit
    
    int apHeading = 0;          // This is a variable used to store the Auto Pilot Heading value recieved from Flight Simulator
    int apAltitude = 0;         // This is a variable used to store the Auto Pilot Altitude
    
    const boolean displayLeadingZeros = true; // This is a constant used to determine if we should be displaying leading zeros
    
    void setup() {
      // Initialize all of the output pins
      pinMode(pinSegmentA, OUTPUT);        // TOP of segment
      pinMode(pinSegmentB, OUTPUT);        // TOP RIGHT of segment
      pinMode(pinSegmentC, OUTPUT);        // BOTTOM RIGHT of segment
      pinMode(pinSegmentD, OUTPUT);        // BOTTOM of segment
      pinMode(pinSegmentE, OUTPUT);        // BOTTOM LEFT of segment
      pinMode(pinSegmentF, OUTPUT);        // TOP LEFT of segment
      pinMode(pinSegmentG, OUTPUT);        // MIDDLE of segment
      pinMode(pinDigitHundreds, OUTPUT);   // Common Annode of segment 1
      pinMode(pinDigitTens, OUTPUT);       // Common Annode of segment 2
      pinMode(pinDigitOnes, OUTPUT);       // Common Annode of segment 3
      
      // initialize the serial port and it's speed
      Serial.begin(115200);  
    }
    
    void loop() {
      // put your main code here, to run repeatedly: 
      displayValue(apHeading);    // continously display the value on the 7-segment displays
      
      // If there is data in the serial buffer than it should be read
      if (Serial.available() > 0) {
        ReadSerialInput();
      }
    }
    
    void ReadSerialInput () {
     // This function reads the values from the serial interface
     int j1;
     j1 = Serial.read();
     
     // Check for the "autopilot apHeading"
     if (j1 == 'r') {
       delay(11);  // It seems to require a small delay before reading the next character
       apHeading = 0;
       apHeading = AddSerialDigit (Serial.read(), apHeading);  // Read the first character and convert it to a digit which is attached to the integer
       apHeading = AddSerialDigit (Serial.read(), apHeading);  // Read the second character and convert it to a digit which is attached to the integer
       apHeading = AddSerialDigit (Serial.read(), apHeading);  // Read the third character and convert it to a digit which is attached to the integer
       // Serial.print("apHeading - ");
       // Serial.println(apHeading);
     }
     
     // Each reading required would be added here
     if (j1 == 'p') {
       delay(11);  // It seems to require a small delay before reading the next character
       apAltitude = 0;
       apAltitude = AddSerialDigit (Serial.read(), apAltitude);  // Read the first character and convert it to a digit which is attached to the integer
       apAltitude = AddSerialDigit (Serial.read(), apAltitude);  // Read the second character and convert it to a digit which is attached to the integer
       apAltitude = AddSerialDigit (Serial.read(), apAltitude);  // Read the third character and convert it to a digit which is attached to the integer
       apAltitude = AddSerialDigit (Serial.read(), apAltitude);  // Read the forth character and convert it to a digit which is attached to the integer
       apAltitude = AddSerialDigit (Serial.read(), apAltitude);  // Read the fith character and convert it to a digit which is attached to the integer
       // Serial.print("apAltitude - ");
       // Serial.println(apAltitude);
     }
    }
    
    int AddSerialDigit (int inByte, int inValue) {
     // this function add the incoming byte read from the serial port to an incoming value
     // example: inbyte is an integer of 3 and incoming value is 46 then the result is 463
      return ((inValue * 10) + CharToInteger(inByte)); 
    }
    
    int CharToInteger (int inByte) {
      // This function converts an incoming Char(byte) to an actual integer...
      
      switch (inByte) {
        case '1':
          return 1;
          break;
        case '2':
          return 2;
          break;
        case '3':
          return 3;
          break;
        case '4':
          return 4;
          break;
        case '5':
          return 5;
          break;
        case '6':
          return 6;
          break;
        case '7':
          return 7;
          break;
        case '8':
          return 8;
          break;
        case '9':
          return 9;
          break;
        default:
          return 0;
          break;
      }
    }
    
    void displayValue(int incomingValue) {
    
      boolean displayTens = false;                // This boolean is used to decide if we should show the tens digit.
      // in other word, the number may be 100 so the tens zero needs to be
      // displayed regardless of the value
    
        if ((incomingValue > 99) || (displayLeadingZeros == true)) {
        // If the value is greater than 99 than there is a hundreds digit to display
        // or we want to display a leading zero
    
        if (incomingValue > 299) {
          DisplayDigit (3, 1);                    // Display the number 3 in the hundreds place
          incomingValue = incomingValue - 300;    // subtract 300 from the value so we are leftover with the tens and ones
          displayTens = true;                     // we will need to display the tens value
        }
        else if (incomingValue > 199) {
          DisplayDigit (2, 1);                    // Display the number 2 in the hundreds place
          incomingValue = incomingValue - 200;    // subtract 200 from the value so we are leftover with the tens and ones
          displayTens = true;                     // we will need to display the tens value
        }
        else if (incomingValue > 99) {
          DisplayDigit (1, 1);                    // Display the number 1 in the hundreds place
          incomingValue = incomingValue - 100;    // subtract 300 from the value so we are leftover with the tens and ones
          displayTens = true;                     // we will need to display the tens value
        }
        else {
          DisplayDigit (0, 1);                    // Display the number 0 in the hundreds place
        }
      }
      if ((incomingValue > 9) || (displayLeadingZeros == true) || (displayTens = true)) {
        // If the value is greater than 99 than there is a hundreds digit to display
        // or we want to display a leading zero
    
        if (incomingValue > 89) {
          DisplayDigit (9, 2);                    // Display the number 9 in the tens place
          incomingValue = incomingValue - 90;    // subtract 90 from the value so we are leftover with the ones
        }
        else if (incomingValue > 79) {
          DisplayDigit (8, 2);                    // Display the number 8 in the tens place
          incomingValue = incomingValue - 80;    // subtract 80 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 69) {
          DisplayDigit (7, 2);                    // Display the number 7 in the tens place
          incomingValue = incomingValue - 70;    // subtract 70 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 59) {
          DisplayDigit (6, 2);                    // Display the number 6 in the tens place
          incomingValue = incomingValue - 60;    // subtract 60 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 49) {
          DisplayDigit (5, 2);                    // Display the number 5 in the tens place
          incomingValue = incomingValue - 50;    // subtract 50 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 39) {
          DisplayDigit (4, 2);                    // Display the number 4 in the tens place
          incomingValue = incomingValue - 40;    // subtract 40 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 29) {
          DisplayDigit (3, 2);                    // Display the number 3 in the tens place
          incomingValue = incomingValue - 30;    // subtract 30 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 19) {
          DisplayDigit (2, 2);                    // Display the number 2 in the tens place
          incomingValue = incomingValue - 20;    // subtract 20 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 9) {
          DisplayDigit (1, 2);                    // Display the number 1 in the tens place
          incomingValue = incomingValue - 10;    // subtract 10 from the value so we are leftover with the tens and ones
        }
        else {
          DisplayDigit (0, 2);                    // Display the number 0 in the tens place
        }
      }
    
      if (incomingValue > 8) {
        DisplayDigit (9, 3);                    // Display the number 9 in the ones place
      }
      else if (incomingValue > 7) {
        DisplayDigit (8, 3);                    // Display the number 8 in the ones place
      }
      else if (incomingValue > 6) {
        DisplayDigit (7, 3);                    // Display the number 7 in the ones place
      }
      else if (incomingValue > 5) {
        DisplayDigit (6, 3);                    // Display the number 6 in the ones place
      }
      else if (incomingValue > 4) {
        DisplayDigit (5, 3);                    // Display the number 5 in the ones place
      }
      else if (incomingValue > 3) {
        DisplayDigit (4, 3);                    // Display the number 4 in the ones place
      }
      else if (incomingValue > 2) {
        DisplayDigit (3, 3);                    // Display the number 3 in the ones place
      }
      else if (incomingValue > 1) {
        DisplayDigit (2, 3);                    // Display the number 2 in the ones place
      }
      else if (incomingValue > 0) {
        DisplayDigit (1, 3);                    // Display the number 1 in the ones place
      }
      else {
        DisplayDigit (0, 3);                    // Display the number 0 in the ones place
      }
    
    
    
    }
    
    
    void DisplayDigit(int DigitToDisplay, int PlaceToDisplay) {
      // This function displays a digit in a location
      // digit should be 0 through 9
      // place should be 1 through 3 (1 being hundred, 2 being tens, 3 being ones place holder)
    
      // Turn Off All Digits
      digitalWrite(pinDigitHundreds, LOW);    // turn the Hundreds Digit Off
      digitalWrite(pinDigitTens, LOW);        // turn the Tens Digit Off
      digitalWrite(pinDigitOnes, LOW);        // turn the Ones Digit Off
    
      switch (DigitToDisplay) {
      case 0: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, LOW);    // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, HIGH);   // MIDDLE
          break;
        }
      case 1: 
        {
          digitalWrite(pinSegmentA, HIGH);   // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, HIGH);   // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, HIGH);   // TOP LEFT
          digitalWrite(pinSegmentG, HIGH);   // MIDDLE
          break;
        }
      case 2: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, HIGH);   // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, LOW);    // BOTTOM LEFT
          digitalWrite(pinSegmentF, HIGH);   // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 3: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, HIGH);   // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 4: 
        {
          digitalWrite(pinSegmentA, HIGH);   // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, HIGH);   // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 5: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, HIGH);   // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 6: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, HIGH);   // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, LOW);    // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 7: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, HIGH);   // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, HIGH);   // TOP LEFT
          digitalWrite(pinSegmentG, HIGH);   // MIDDLE
          break;
        }
      case 8: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, LOW);    // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 9: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, HIGH);   // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      }
    
      switch(PlaceToDisplay) {
      case 1: 
        {
          digitalWrite(pinDigitHundreds, HIGH);    // turn the Hundreds Digit ON
          break;
        }
      case 2: 
        {
          digitalWrite(pinDigitTens, HIGH);        // turn the Tens Digit ON
          break;
        }
      case 3: 
        {
          digitalWrite(pinDigitOnes, HIGH);        // turn the Ones Digit ON
          break;
        }
      }
    
      // wait 5 milliseconds, this makes sure that the digit is shown long enough before looping
      delay(5); 
    }

  5. #4
    25+ Posting Member
    Join Date
    Apr 2012
    Location
    New Zealand
    Posts
    35
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Seeking help combining Sketchs.......

    Apaltitude Sketch










    Code:
          
    #include 
    
    
    Encoder knobLeft(2, 3);
    int pinSegmentA = 4;        // Connect this pin to all 7-digit displays for the "A" segment
    int pinSegmentB = 5;        // Connect this pin to all 7-digit displays for the "B" segment
    int pinSegmentC = 6;        // Connect this pin to all 7-digit displays for the "C" segment
    int pinSegmentD = 7;        // Connect this pin to all 7-digit displays for the "D" segment
    int pinSegmentE = 8;        // Connect this pin to all 7-digit displays for the "E" segment
    int pinSegmentF = 9;        // Connect this pin to all 7-digit displays for the "F" segment
    int pinSegmentG = 10;        // Connect this pin to all 7-digit displays for the "G" segment
    //int AltitudeEncoderPinA = 12;     // Connected Altitude Encoder Pin A (External Interupt Pin)
    //int AltitudeEncoderPinB = 13;     // Connected Altitude Encoder Pin B
          // Connect this pin to a resistor (around 100 ohms) and the other end of the resistor to the common annode pin of the 7-segment display for "Ones" Digit
    int pinDigitTenthousands = 11;
    int pinDigitThousands = 12;
    int pinDigitHundreds = 13;
    int pinDigitTens = 22;      // Connect this pin to a resistor (around 100 ohms) and the other end of the resistor to the common annode pin of the 7-segment display for "Tens" Digit
    int pinDigitOnes = 24;// Connect this pin to a resistor (around 100 ohms) and the other end of the resistor to the common annode pin of the 7-segment display for "Hundreds" Digit
       // Connect this pin to a resistor (around 100 ohms) and the other end of the resistor to the common annode pin of the 7-segment display for "Thousands" Digit   
     // Connect this pin to a resistor (around 100 ohms) and the other end of the resistor to the common annode pin of the 7-segment display for "Tenthousands" Digit
    
    int apAltitude = 0;         // This is a variable used to store the Auto Pilot Altitude
    
    const boolean displayLeadingZeros = true; // This is a constant used to determine if we should be displaying leading zeros
    
    void setup() {
      pinMode(pinSegmentA, OUTPUT);        // TOP of segment
      pinMode(pinSegmentB, OUTPUT);        // TOP RIGHT of segment
      pinMode(pinSegmentC, OUTPUT);        // BOTTOM RIGHT of segment
      pinMode(pinSegmentD, OUTPUT);        // BOTTOM of segment
      pinMode(pinSegmentE, OUTPUT);        // BOTTOM LEFT of segment
      pinMode(pinSegmentF, OUTPUT);        // TOP LEFT of segment
      pinMode(pinSegmentG, OUTPUT);        // MIDDLE of segment
      
      pinMode(pinDigitOnes, OUTPUT);       // Common Annode of segment 5
      pinMode(pinDigitTens, OUTPUT);       // Common Annode of segment 4
      pinMode(pinDigitHundreds, OUTPUT);   // Common Annode of segment 3
      pinMode(pinDigitThousands, OUTPUT);       // Common Annode of segment 2
      pinMode(pinDigitTenthousands, OUTPUT);       // Common Annode of segment 1
      
     
      Serial.begin(115200);  
    
    }
    long positionLeft  = -999;
    void loop() {
      long newLeft;
      newLeft = knobLeft.read();
      if (newLeft != positionLeft) {
        if (newLeft > positionLeft) {
          Serial.print("D050");
          }
        else if (newLeft < positionLeft) {
          Serial.print("D060");
          }
        positionLeft = newLeft;
      }
    
      // put your main code here, to run repeatedly: 
      displayValue(apAltitude);    // continously display the value on the 7-segment displays
      
      // If there is data in the serial buffer than it should be read
      if (Serial.available() > 0) {
        ReadSerialInput();
      }
    }
    
    void ReadSerialInput () {
     // This function reads the values from the serial interface
     int j1;
     j1 = Serial.read();
     
     if (j1 == 'p') {
       delay(11);  // It seems to require a small delay before reading the next character
       apAltitude = 0;
       apAltitude = AddSerialDigit (Serial.read(), apAltitude);  // Read the first character and convert it to a digit which is attached to the integer
       apAltitude = AddSerialDigit (Serial.read(), apAltitude);  // Read the second character and convert it to a digit which is attached to the integer
       apAltitude = AddSerialDigit (Serial.read(), apAltitude);  // Read the third character and convert it to a digit which is attached to the integer
       apAltitude = AddSerialDigit (Serial.read(), apAltitude);  // Read the forth character and convert it to a digit which is attached to the integer
       apAltitude = AddSerialDigit (Serial.read(), apAltitude);  // Read the fith character and convert it to a digit which is attached to the integer
       Serial.print("apAltitude - ");
       Serial.println(apAltitude);
     }
    }
    
    int AddSerialDigit (int inByte, int inValue) {
     // this function add the incoming byte read from the serial port to an incoming value
     // example: inbyte is an integer of 3 and incoming value is 46 then the result is 463
      return ((inValue * 10) + CharToInteger(inByte)); 
    }
    
    int CharToInteger (int inByte) {
      // This function converts an incoming Char(byte) to an actual integer...
      
      switch (inByte) {
        case '1':
          return 1;
          break;
        case '2':
          return 2;
          break;
        case '3':
          return 3;
          break;
        case '4':
          return 4;
          break;
        case '5':
          return 5;
          break;
        case '6':
          return 6;
          break;
        case '7':
          return 7;
          break;
        case '8':
          return 8;
          break;
        case '9':
          return 9;
          break;
        default:
          return 0;
          break;
      }
    }
    
    void displayValue(int incomingValue) {
      
      boolean isNegative = false;
      //boolean firstDigitFound = false;
     // boolean displayOnes = false;
     boolean displayTenthousands = false;
     boolean displayThousands = false;
     boolean displayHundreds = false; 
     boolean displayTens = false;  
    
    
    
    if (incomingValue < 0) {
        isNegative = true;
       incomingValue = incomingValue * -1;
      }
     if ((incomingValue > 9999) || (displayLeadingZeros == true)) {  
    
     }
       if (incomingValue > 39999) {
        DisplayDigit (4, 1);
         incomingValue = incomingValue - 40000;  // subtract 40,000 from the value so we are leftover with the remaining digits
         displayThousands = true; 
             }
        else if (incomingValue > 29999) {
          DisplayDigit (3, 1);
          incomingValue = incomingValue - 30000;  // subtract 30,000 from the value so we are leftover with the remaining digits
          displayThousands = true; 
           }
        else if (incomingValue > 19999) {
          DisplayDigit (2, 1);
          incomingValue = incomingValue - 20000;  // subtract 20,000 from the value so we are leftover with the remaining digits
          displayThousands = true; 
              }
        else if (incomingValue > 9999) {
          DisplayDigit (1, 1);
             incomingValue = incomingValue -10000;    // subtract 300 from the value so we are leftover with the tens and ones
          displayThousands = true;                     // we will need to display the tens value
        }
         else {
           DisplayDigit (0, 1);
             displayThousands = true;
        }
    
        if ((incomingValue > 999) || (displayLeadingZeros == true) || (displayThousands == true)) {
     
         if (incomingValue > 8999) {
          DisplayDigit (9, 2);                    // Display the number 3 in the hundreds place
          incomingValue = incomingValue -9000;    // subtract 300 from the value so we are leftover with the tens and ones
          displayHundreds = true;                     // we will need to display the tens value
        } 
      
        else if (incomingValue > 7999) {
          DisplayDigit (8, 2);                    // Display the number 3 in the hundreds place
          incomingValue = incomingValue -8000;    // subtract 300 from the value so we are leftover with the tens and ones
          displayHundreds = true;                     // we will need to display the tens value
        }               
        else if (incomingValue > 6999) {
          DisplayDigit (7, 2);                    // Display the number 3 in the hundreds place
          incomingValue = incomingValue -7000;    // subtract 300 from the value so we are leftover with the tens and ones
          displayHundreds = true;                     // we will need to display the tens valu 
        }
        else if (incomingValue > 5999) {
          DisplayDigit (6, 2);                    // Display the number 3 in the hundreds place
          incomingValue = incomingValue -6000;    // subtract 300 from the value so we are leftover with the tens and ones
          displayHundreds = true;                     // we will need to display the tens value   
        }
        else if (incomingValue > 4999) {
          DisplayDigit (5, 2);                    // Display the number 3 in the hundreds place
          incomingValue = incomingValue - 5000;    // subtract 300 from the value so we are leftover with the tens and ones
          displayHundreds = true;                     // we will need to display the tens value
        }
        
    
        else if (incomingValue > 3999) {
        DisplayDigit (4, 2);                    // Display the number 3 in the hundreds place
          incomingValue = incomingValue - 4000;    // subtract 300 from the value so we are leftover with the tens and ones
          displayHundreds = true;                     // we will need to display the tens value
        }
        else if (incomingValue > 2999) {  
          DisplayDigit (3, 2);                    // Display the number 2 in the hundreds place
          incomingValue = incomingValue - 3000;    // subtract 200 from the value so we are leftover with the tens and ones
          displayHundreds = true;                     // we will need to display the tens value
        }    
      
        
        
         else if (incomingValue > 1999) {  
          DisplayDigit (2, 2);                    // Display the number 2 in the hundreds place
          incomingValue = incomingValue - 2000;    // subtract 200 from the value so we are leftover with the tens and ones
          displayHundreds = true;                     // we will need to display the tens value
        } 
     
     else if (incomingValue > 999) {
          DisplayDigit (1, 2);                    // Display the number 3 in the hundreds place
          incomingValue = incomingValue - 1000;    // subtract 300 from the value so we are leftover with the tens and ones
          //displayThousands = true;    
           displayHundreds = true;// we have found our first digit
        }
        
          else {
          DisplayDigit (0, 2);
          displayHundreds = true;
          }      // Display the number 0 in the hundreds place
    
       if ((incomingValue > 99) || (displayLeadingZeros == true) || (displayHundreds == true)) {
       
         if (incomingValue > 899) {
          DisplayDigit (9, 3);                    // Display the number 3 in the hundreds place
          incomingValue = incomingValue - 900;    // subtract 300 from the value so we are leftover with the tens and ones
          displayTens = true;                     // we will need to display the tens value
        }
        else if (incomingValue > 799) {
          DisplayDigit (8, 3);                    // Display the number 2 in the hundreds place
          incomingValue = incomingValue - 800;    // subtract 200 from the value so we are leftover with the tens and ones
          displayTens = true;                     // we will need to display the tens value
        }
         
        else if (incomingValue > 699) {
          DisplayDigit (7, 3);                    // Display the number 3 in the hundreds place
          incomingValue = incomingValue - 700;    // subtract 300 from the value so we are leftover with the tens and ones
          displayTens = true;                     // we will need to display the tens value
        }
        else if (incomingValue > 599) {
          DisplayDigit (6, 3);                    // Display the number 2 in the hundreds place
          incomingValue = incomingValue - 600;    // subtract 200 from the value so we are leftover with the tens and ones
          displayTens = true;                     // we will need to display the tens value
        }
        else if (incomingValue > 499) {
          DisplayDigit (5, 3);                    // Display the number 3 in the hundreds place
          incomingValue = incomingValue - 500;    // subtract 300 from the value so we are leftover with the tens and ones
          displayTens = true;                     // we will need to display the tens value
        }
        else if (incomingValue > 399) {
          DisplayDigit (4, 3);                    // Display the number 2 in the hundreds place
          incomingValue = incomingValue - 400;    // subtract 200 from the value so we are leftover with the tens and ones
          displayTens = true;                     // we will need to display the tens value
        }
        
        else if (incomingValue > 299) {
          DisplayDigit (3, 3);                    // Display the number 3 in the hundreds place
          incomingValue = incomingValue - 300;    // subtract 300 from the value so we are leftover with the tens and ones
          displayTens = true;                     // we will need to display the tens value
        }
        else if (incomingValue > 199) {
          DisplayDigit (2, 3);                    // Display the number 2 in the hundreds place
          incomingValue = incomingValue - 200;    // subtract 200 from the value so we are leftover with the tens and ones
          displayTens = true;                     // we will need to display the tens value
        }
        else if (incomingValue > 99) {
          DisplayDigit (1, 3);                    // Display the number 1 in the hundreds place
          incomingValue = incomingValue - 100;    // subtract 300 from the value so we are leftover with the tens and ones
          displayTens = true;                     // we will need to display the tens value
        }
        else {
          DisplayDigit (0, 3);                    // Display the number 0 in the hundreds place
        }
      }
      
        if (incomingValue > 89) {
          DisplayDigit (9, 4);                    // Display the number 9 in the tens place
          incomingValue = incomingValue - 90;    // subtract 90 from the value so we are leftover with the ones
        }
        else if (incomingValue > 79) {
          DisplayDigit (8, 4);                    // Display the number 8 in the tens place
          incomingValue = incomingValue - 80;    // subtract 80 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 69) {
          DisplayDigit (7, 4);                    // Display the number 7 in the tens place
          incomingValue = incomingValue - 70;    // subtract 70 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 59) {
          DisplayDigit (6, 4);                    // Display the number 6 in the tens place
          incomingValue = incomingValue - 60;    // subtract 60 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 49) {
          DisplayDigit (5, 4);                    // Display the number 5 in the tens place
          incomingValue = incomingValue - 50;    // subtract 50 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 39) {
          DisplayDigit (4, 4);                    // Display the number 4 in the tens place
          incomingValue = incomingValue - 40;    // subtract 40 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 29) {
          DisplayDigit (3, 4);                    // Display the number 3 in the tens place
          incomingValue = incomingValue - 30;    // subtract 30 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 19) {
          DisplayDigit (2, 4);                    // Display the number 2 in the tens place
          incomingValue = incomingValue - 20;    // subtract 20 from the value so we are leftover with the tens and ones
        }
        else if (incomingValue > 9) {
          DisplayDigit (1, 4);                    // Display the number 1 in the tens place
          incomingValue = incomingValue - 10;    // subtract 10 from the value so we are leftover with the tens and ones
        }
        else {
          DisplayDigit (0, 4);                    // Display the number 0 in the tens place
        }
      }
    
      if (incomingValue > 8) {
        DisplayDigit (9, 5);                    // Display the number 9 in the ones place
      }
      else if (incomingValue > 7) {
        DisplayDigit (8, 5);                    // Display the number 8 in the ones place
      }
      else if (incomingValue > 6) {
        DisplayDigit (7, 5);                    // Display the number 7 in the ones place
      }
      else if (incomingValue > 5) {
        DisplayDigit (6, 5);                    // Display the number 6 in the ones place
      }
      else if (incomingValue > 4) {
        DisplayDigit (5, 5);                    // Display the number 5 in the ones place
      }
      else if (incomingValue > 3) {
        DisplayDigit (4, 5);                    // Display the number 4 in the ones place
      }
      else if (incomingValue > 2) {
        DisplayDigit (3, 5);                    // Display the number 3 in the ones place
      }
      else if (incomingValue > 1) {
        DisplayDigit (2, 5);                    // Display the number 2 in the ones place
      }
      else if (incomingValue > 0) {
        DisplayDigit (1, 5);                    // Display the number 1 in the ones place
      }
      else {
        DisplayDigit (0, 5);                    // Display the number 0 in the ones place
      }
    
      }
    
    
    
    
    void DisplayDigit(int DigitToDisplay, int PlaceToDisplay){
    
      digitalWrite(pinDigitTenthousands, LOW);    // turn the Hundreds Digit Off
      digitalWrite(pinDigitThousands, LOW); 
      digitalWrite(pinDigitHundreds, LOW);    // turn the Hundreds Digit Off
      digitalWrite(pinDigitTens, LOW);        // turn the Tens Digit Off
      digitalWrite(pinDigitOnes, LOW);        // turn the Ones Digit Off
    
      switch (DigitToDisplay) {
      case 0: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, LOW);    // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, HIGH);   // MIDDLE
          break;
        }
      case 1: 
        {
          digitalWrite(pinSegmentA, HIGH);   // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, HIGH);   // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, HIGH);   // TOP LEFT
          digitalWrite(pinSegmentG, HIGH);   // MIDDLE
          break;
        }
      case 2: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, HIGH);   // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, LOW);    // BOTTOM LEFT
          digitalWrite(pinSegmentF, HIGH);   // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 3: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, HIGH);   // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 4: 
        {
          digitalWrite(pinSegmentA, HIGH);   // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, HIGH);   // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 5: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, HIGH);   // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 6: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, HIGH);   // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, LOW);    // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 7: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, HIGH);   // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, HIGH);   // TOP LEFT
          digitalWrite(pinSegmentG, HIGH);   // MIDDLE
          break;
        }
      case 8: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, LOW);    // BOTTOM
          digitalWrite(pinSegmentE, LOW);    // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      case 9: 
        {
          digitalWrite(pinSegmentA, LOW);    // TOP
          digitalWrite(pinSegmentB, LOW);    // TOP RIGHT
          digitalWrite(pinSegmentC, LOW);    // BOTTOM RIGHT
          digitalWrite(pinSegmentD, HIGH);   // BOTTOM
          digitalWrite(pinSegmentE, HIGH);   // BOTTOM LEFT
          digitalWrite(pinSegmentF, LOW);    // TOP LEFT
          digitalWrite(pinSegmentG, LOW);    // MIDDLE
          break;
        }
      }
    
      switch(PlaceToDisplay) {
      case 1: 
      
      
      {
          digitalWrite(pinDigitTenthousands, HIGH);    // turn the Hundreds Digit ON
          break;
        }
      case 2: 
        {
          digitalWrite(pinDigitThousands, HIGH);        // turn the Tens Digit ON
          break;
        }
      
      case 3:   
      
        {
          digitalWrite(pinDigitHundreds, HIGH);    // turn the Hundreds Digit ON
          break;
        }
      case 4: 
        {
          digitalWrite(pinDigitTens, HIGH);        // turn the Tens Digit ON
          break;
        }
      case 5: 
        {
          digitalWrite(pinDigitOnes, HIGH);        // turn the Ones Digit ON
          break;
        }
      }
    
     delay(5); 
    }