/*
 * File Name: NOT.h 
*/
            /***********************************************************************************************************************************
                                                       --------Truth Table for Hex 7404 NOT Chip----------
            /***********************************************************************************************************************************/
                                              /*  Input A  | Output #1 Output #2 Output #3 Output #4 Output #5 Output #6
                                                    1      |    0         0         0         0         0         0     Test 1
                                                    0      |    1         1         1         1         1         1     Test 2
                                              */
boolean NOT()
{
                                                                     /*      ------------      */  
                                                int not_A1=FP;       /*  1A  |   \_/    | VCC  */  int notVcc=FP+1;
                                                int not_R1=FP+2;     /*  1Y  |          | 6A   */  int not_A6=FP+3;    
                                                int not_A2=FP+4;     /*  2A  |          | 6Y   */  int not_R6=FP+5;
                                                int not_R2=FP+6;     /*  2Y  |          | 5A   */  int not_A5=FP+7; 
                                                int not_A3=FP+8;     /*  3A  |          | 5Y   */  int not_R5=FP+9;
                                                int not_R3=FP+10;    /*  3Y  |          | 4A   */  int not_A4=FP+11; 
                                                int notGND=FP+12;    /*  GND |          | 4Y   */  int not_R4=FP+13; 
                                                                     /*      ------------      */ 
                                                                             int not_G1;
                                                                             int not_G2;
                                                                             int not_G3;
                                                                             int not_G4;
                                                                             int not_G5;
                                                                             int not_G6;
                                                                         boolean test1 = false;
                                                                         boolean test2 = false;
                                                                         boolean test3 = false;
                                                                         boolean test4 = false;
                                                                         boolean test5 = false;
                                                                         boolean test6 = false;
          
                                                          pinMode(not_A1, OUTPUT);  pinMode(notVcc, OUTPUT);
                                                          pinMode(not_R1, INPUT);   pinMode(not_A6, OUTPUT);
                                                          pinMode(not_A2, OUTPUT);  pinMode(not_R6, INPUT);
                                                          pinMode(not_R2, INPUT);   pinMode(not_A5, OUTPUT);
                                                          pinMode(not_A3, OUTPUT);  pinMode(not_R5, INPUT);
                                                          pinMode(not_R3, INPUT);   pinMode(not_A4, OUTPUT);
                                                          pinMode(notGND, OUTPUT);  pinMode(not_R4, INPUT);

/**********************************************************************************
            ------------------------TEST 1------------------------
 **********************************************************************************/                                                 
        Serial.println("Testing with 1");
        digitalWrite(notGND, LOW); digitalWrite(notVcc, HIGH);
        delay(readDelay);

        digitalWrite(not_A1, HIGH); digitalWrite(not_A6, HIGH);
        digitalWrite(not_A2, HIGH); digitalWrite(not_A5, HIGH);
        digitalWrite(not_A3, HIGH); digitalWrite(not_A4, HIGH);
        delay(readDelay);
         
        not_G1 = digitalRead(not_R1); Serial.print("Gate 1: "); Serial.print(not_G1);
        not_G2 = digitalRead(not_R2); Serial.print("\nGate 2: "); Serial.print(not_G2);
        not_G3 = digitalRead(not_R3); Serial.print("\nGate 3: "); Serial.print(not_G3);
        not_G4 = digitalRead(not_R4); Serial.print("\nGate 4: "); Serial.print(not_G4);
        not_G5 = digitalRead(not_R3); Serial.print("\nGate 5: "); Serial.print(not_G3);
        not_G6 = digitalRead(not_R4); Serial.print("\nGate 6: "); Serial.print(not_G4);
        
        if(not_G1 == 0 && 
           not_G2 == 0 && 
           not_G3 == 0 && 
           not_G4 == 0 && 
           not_G5 == 0 && 
           not_G6 == 0)
           {
              test1 = true;
           } 
           Serial.print("\nResult: ");
           Serial.println(test1);
        
/**********************************************************************************
            ------------------------TEST 2------------------------
 **********************************************************************************/  
        Serial.println("Testing with 0");
        digitalWrite(notGND, LOW); digitalWrite(notVcc, HIGH);
        delay(readDelay);

        digitalWrite(not_A1, LOW); digitalWrite(not_A6, LOW);
        digitalWrite(not_A2, LOW); digitalWrite(not_A5, LOW);
        digitalWrite(not_A3, LOW); digitalWrite(not_A4, LOW);
        
        not_G1 = digitalRead(not_R1); Serial.print("Gate 1: "); Serial.print(not_G1);
        not_G2 = digitalRead(not_R2); Serial.print("\nGate 2: "); Serial.print(not_G2);
        not_G3 = digitalRead(not_R3); Serial.print("\nGate 3: "); Serial.print(not_G3);
        not_G4 = digitalRead(not_R4); Serial.print("\nGate 4: "); Serial.print(not_G4);
        not_G5 = digitalRead(not_R3); Serial.print("\nGate 5: "); Serial.print(not_G3);
        not_G6 = digitalRead(not_R4); Serial.print("\nGate 6: "); Serial.print(not_G4);
        
        if(not_G1 == 1 && 
           not_G2 == 1 && 
           not_G3 == 1 && 
           not_G4 == 1 && 
           not_G5 == 1 && 
           not_G6 == 1)
           {
              test2 = true;
           }    
           Serial.print("\nResult: ");   
           Serial.println(test2);

/**********************************************************************************
            ------------------------NOT RESULTS------------------------
 **********************************************************************************/             
        if(test1 == true && 
           test2 == true)
        {
          test1 = test2 = false;
          return 1;
        }
        else
        {
          test1 = test2 = false;
          return 0;
        }
}
