231a-ag temporary code

From CSclasswiki
Jump to: navigation, search

Temporary Place to Store Code

/*
 * Hardware Testing
 *
 * Program that tests the Arduino hardware.
 *
 */

char buffer[256];
int len;
char *operation;
char *mode;
char *pin;
char *state;

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;

int lastKey = 0;
int firstKey = 0;
int secondKey = 0;
int thirdKey = 0;

int analogReadPin = 0;
int digitalReadPin = 0;

// SETUP
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);
  delay(3000);
  digitalWrite(ledPin7, HIGH);
  digitalWrite(ledPin8, HIGH);
  digitalWrite(ledPin9, LOW);
  digitalWrite(ledPin10, HIGH);
  digitalWrite(ledPin11, LOW);
  digitalWrite(ledPin12, LOW);  
  delay(1000);
  digitalWrite(ledPin9, HIGH);
  digitalWrite(ledPin10, LOW);
      
  digitalWrite(ledPin7, HIGH);
  digitalWrite(ledPin8, HIGH);
  digitalWrite(ledPin9, LOW);
  digitalWrite(ledPin10, LOW);
  digitalWrite(ledPin11, HIGH);
  digitalWrite(ledPin12, LOW);
  delay(1000);
  digitalWrite(ledPin9, HIGH);
  digitalWrite(ledPin11, LOW);
       
  digitalWrite(ledPin7, HIGH);
  digitalWrite(ledPin8, HIGH);
  digitalWrite(ledPin9, LOW);
  digitalWrite(ledPin10, LOW);
  digitalWrite(ledPin11, LOW);
  digitalWrite(ledPin12, HIGH);  
  delay(1000);
  digitalWrite(ledPin9, HIGH);
  digitalWrite(ledPin12, LOW);
}

// RESETALL
void resetAll() {
   buffer[0] = '\0';
   len = 0;
   operation = mode = pin = state = 0;
}

void loop() {                        // run over and over again
  digitalWrite(keypadDPin3, LOW);
  digitalWrite(keypadDPin4, LOW);
  digitalWrite(keypadDPin5, LOW);

  padNumber3 = analogRead(keypadAPin0);
  padNumber1 = analogRead(keypadAPin1);
  padNumber5 = analogRead(keypadAPin2);
 
  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);
      lastKey = 1;
    }
    
    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);
      lastKey = 4;
    }  
    
    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);
      lastKey = 7;
    }
  } else if (padNumber1 < 200) {
     digitalWrite(keypadDPin3, HIGH);
     digitalWrite(keypadDPin4, HIGH);
     digitalWrite(keypadDPin5, LOW);  // Is it 2?
     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);
       lastKey = 2;
     }
    
     digitalWrite(keypadDPin3, HIGH);
     digitalWrite(keypadDPin4, LOW);
     digitalWrite(keypadDPin5, HIGH);  // Is it 5?
     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);
       lastKey = 5;
     }
       
     digitalWrite(keypadDPin3, LOW);
     digitalWrite(keypadDPin4, HIGH);
     digitalWrite(keypadDPin5, HIGH);  // Is it 8?
     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);
       lastKey = 8;
     }
  } else if (padNumber5 < 200) {
      digitalWrite(keypadDPin3, HIGH);
      digitalWrite(keypadDPin4, HIGH);
      digitalWrite(keypadDPin5, LOW);  // Is it 3?
      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);
       lastKey = 3;
      }
      
      digitalWrite(keypadDPin3, HIGH);
      digitalWrite(keypadDPin4, LOW);
      digitalWrite(keypadDPin5, HIGH);  // Is it 6?
      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);
        lastKey = 6;
      }
      
      digitalWrite(keypadDPin3, LOW);
      digitalWrite(keypadDPin4, HIGH);
      digitalWrite(keypadDPin5, HIGH);  // Is it 9?
      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);
        lastKey = 9;
      }
  }
  //Serial.print(lastKey);
  if (firstKey == 0) {
    firstKey = lastKey;
  } else if (secondKey == 0) {
    if (lastKey != firstKey) {
      secondKey = lastKey;
    }
  } else if (thirdKey == 0) {
      if (lastKey != secondKey) {
        thirdKey = lastKey;
      }
  }
  Serial.print(firstKey);
  Serial.print(secondKey);
  Serial.print(thirdKey);
  if (firstKey == 1) {
    if (secondKey == 2) {
      if (thirdKey == 3) {
        digitalWrite(buzzerPin, HIGH);
      }
    }
  } else {
    digitalWrite(buzzerPin, LOW);
  }
}



keypadInput:
	mov     al, byte[firstE]
        cmp     al, "0"
        je      firstKeypad
        mov     al, byte[secondE]
	cmp     al, "0"
        je      secondKeypad

        ret

firstKeypad:
        mov     al, [buffer]
        cmp     al, byte[first]
        jne     wrong
        mov     [firstE], al
        call    readPins

secondKeypad:
	mov     al, [buffer]
        cmp     al, byte[firstE]
        je      readPins
        cmp     al, byte[second]
	jne     wrong
        mov     [secondE], al
	call    readPins

wrong: