231a-ag arduinosketch

From CSclasswiki
Jump to: navigation, search
/*
 * Hardware Testing
 *
 * Program that tests the Arduino hardware.
 *
 */

int ledPin7 = 7;
int ledPin8 = 8;                   // LED connected to digital pin 8 and 12
int ledPin9 = 9;

int ledPin10 = 10;
int ledPin11 = 11;
int ledPin12 = 12;

int buzzerPin = 13;

int keypadDPin3 = 3;
int keypadDPin4 = 4;
int keypadDPin5 = 5;

int keypadAPin0 = 0;
int keypadAPin1 = 1;
int keypadAPin2 = 2;

int padNumber3 = 0;
int padNumber3a = 0;
int padNumber3b = 0;
int padNumber1 = 0;
int padNumber5 = 0;

int padNumber2 = 0;
int padNumber7 = 0;
int padNumber6 = 0;

void setup()                       // run once, when the sketch starts
{
  pinMode(ledPin7, OUTPUT);         // sets the digital pin as output
  pinMode(ledPin8, OUTPUT);
  pinMode(ledPin9, OUTPUT);
  pinMode(ledPin10, OUTPUT);
  pinMode(ledPin11, OUTPUT);
  pinMode(ledPin12, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  
  pinMode(keypadDPin3, OUTPUT);
  pinMode(keypadDPin4, OUTPUT);
  pinMode(keypadDPin5, OUTPUT);
  
  pinMode(keypadAPin0, INPUT);
  pinMode(keypadAPin1, INPUT);
  pinMode(keypadAPin2, INPUT);
  
  Serial.begin(9600);
}

void loop() {                        // run over and over again
  digitalWrite(buzzerPin, LOW);    // sets buzzer on

  digitalWrite(keypadDPin3, LOW);
  digitalWrite(keypadDPin4, LOW);
  digitalWrite(keypadDPin5, LOW);

  padNumber3 = analogRead(keypadAPin0);
  padNumber1 = analogRead(keypadAPin1);
  padNumber5 = analogRead(keypadAPin2);
 
  //Serial.println(padNumber1);
 
  if (padNumber3 < 200) {
    digitalWrite(keypadDPin3, HIGH);
    digitalWrite(keypadDPin4, HIGH);
    digitalWrite(keypadDPin5, LOW);  // Is it 1?
    padNumber3 = analogRead(keypadAPin0);
  
    if (padNumber3 < 200) {    // KEY PRESSED IS 1
      digitalWrite(ledPin7, HIGH);
      digitalWrite(ledPin8, HIGH);
      digitalWrite(ledPin9, LOW);
      digitalWrite(ledPin10, HIGH);
      digitalWrite(ledPin11, LOW);
      digitalWrite(ledPin12, LOW);  
      delay(100);
      digitalWrite(ledPin9, HIGH);
      digitalWrite(ledPin10, LOW);
    }
    
    digitalWrite(keypadDPin3, HIGH);
    digitalWrite(keypadDPin4, LOW);
    digitalWrite(keypadDPin5, HIGH);  // Is it 4?
    padNumber3 = analogRead(keypadAPin0);
  
    if (padNumber3 < 200) {    //  KEY PRESSED IS 4
      digitalWrite(ledPin7, HIGH);
      digitalWrite(ledPin8, LOW);
      digitalWrite(ledPin9, HIGH);
      digitalWrite(ledPin10, HIGH);
      digitalWrite(ledPin11, LOW);
      digitalWrite(ledPin12, LOW);  
      delay(100);
      digitalWrite(ledPin8, HIGH);
      digitalWrite(ledPin10, LOW);
    }  
    
    digitalWrite(keypadDPin3, LOW);
    digitalWrite(keypadDPin4, HIGH);
    digitalWrite(keypadDPin5, HIGH);  // Is it 7?
    padNumber3 = analogRead(keypadAPin0);
  
    if (padNumber3 < 200) {    // KEY PRESSED IS 7
      digitalWrite(ledPin7, LOW);
      digitalWrite(ledPin8, HIGH);
      digitalWrite(ledPin9, HIGH);
      digitalWrite(ledPin10, HIGH);
      digitalWrite(ledPin11, LOW);
      digitalWrite(ledPin12, LOW);  
      delay(100);
      digitalWrite(ledPin7, HIGH);
      digitalWrite(ledPin10, LOW);
    }
  } else if (padNumber1 < 200) {
     digitalWrite(keypadDPin3, HIGH);
     digitalWrite(keypadDPin4, HIGH);
     digitalWrite(keypadDPin5, LOW);
     padNumber1 = analogRead(keypadAPin1);
     
     if (padNumber1 < 200) {    // KEY PRESSED IS 2
       digitalWrite(ledPin7, HIGH);
       digitalWrite(ledPin8, HIGH);
       digitalWrite(ledPin9, LOW);
       digitalWrite(ledPin10, LOW);
       digitalWrite(ledPin11, HIGH);
       digitalWrite(ledPin12, LOW);
       delay(100);
       digitalWrite(ledPin9, HIGH);
       digitalWrite(ledPin11, LOW);
     }
    
     digitalWrite(keypadDPin3, HIGH);
     digitalWrite(keypadDPin4, LOW);
     digitalWrite(keypadDPin5, HIGH);
     padNumber1 = analogRead(keypadAPin1);
     
     if (padNumber1 < 200) {    // KEY PRESSED IS 5
       digitalWrite(ledPin7, HIGH);
       digitalWrite(ledPin8, LOW);
       digitalWrite(ledPin9, HIGH);
       digitalWrite(ledPin10, LOW);
       digitalWrite(ledPin11, HIGH);
       digitalWrite(ledPin12, LOW);
       delay(100);
       digitalWrite(ledPin8, HIGH);
       digitalWrite(ledPin11, LOW);
     }
       
     digitalWrite(keypadDPin3, LOW);
     digitalWrite(keypadDPin4, HIGH);
     digitalWrite(keypadDPin5, HIGH);
     padNumber1 = analogRead(keypadAPin1);
     
     if (padNumber1 < 200) {    // KEY PRESSED IS 8
       digitalWrite(ledPin7, LOW);
       digitalWrite(ledPin8, HIGH);
       digitalWrite(ledPin9, HIGH);
       digitalWrite(ledPin10, LOW);
       digitalWrite(ledPin11, HIGH);
       digitalWrite(ledPin12, LOW);  
       delay(100);
       digitalWrite(ledPin7, HIGH);
       digitalWrite(ledPin11, LOW);
     }
  } else if (padNumber5 < 200) {
      digitalWrite(keypadDPin3, HIGH);
      digitalWrite(keypadDPin4, HIGH);
      digitalWrite(keypadDPin5, LOW);
      padNumber5 = analogRead(keypadAPin2);
      
      if (padNumber5 < 200) {    // KEY PRESSED IS 3
       digitalWrite(ledPin7, HIGH);
       digitalWrite(ledPin8, HIGH);
       digitalWrite(ledPin9, LOW);
       digitalWrite(ledPin10, LOW);
       digitalWrite(ledPin11, LOW);
       digitalWrite(ledPin12, HIGH);  
       delay(100);
       digitalWrite(ledPin9, HIGH);
       digitalWrite(ledPin12, LOW);
      }
      
      digitalWrite(keypadDPin3, HIGH);
      digitalWrite(keypadDPin4, LOW);
      digitalWrite(keypadDPin5, HIGH);
      padNumber5 = analogRead(keypadAPin2);
      
      if (padNumber5 < 200) {    // KEY PRESSED IS 6
        digitalWrite(ledPin7, HIGH);
        digitalWrite(ledPin8, LOW);
        digitalWrite(ledPin9, HIGH);  
        digitalWrite(ledPin10, LOW);
        digitalWrite(ledPin11, LOW);
        digitalWrite(ledPin12, HIGH);
        delay(100);
        digitalWrite(ledPin8, HIGH);
        digitalWrite(ledPin12, LOW);
      }
      
      digitalWrite(keypadDPin3, LOW);
      digitalWrite(keypadDPin4, HIGH);
      digitalWrite(keypadDPin5, HIGH);
      padNumber5 = analogRead(keypadAPin2);
      
      if (padNumber5 < 200) {    // KEY PRESSED IS 9
        digitalWrite(ledPin7, LOW);
        digitalWrite(ledPin8, HIGH);
        digitalWrite(ledPin9, HIGH);
        digitalWrite(ledPin10, LOW);
        digitalWrite(ledPin11, LOW);
        digitalWrite(ledPin12, HIGH);
        delay(100);
        digitalWrite(ledPin7, HIGH);
        digitalWrite(ledPin12, LOW);
      }  
    }
}