Go Down

Topic: Trouble with our Keypad Code (Read 937 times) previous topic - next topic

SpecialTopix

Hello fellow programmers!
It's a late night here at CCM, having trouble with our Midterm for our Special Topics Class. Our code is having a lot of syntax problems, and we are having exceptional difficulty making the (##) portion of our assignment, as (#) also funtions as an enter key as well. Here is the official assignment:
Four Digit Key PAD UN-LOCK- CODE
   RED/GREEN LED is Flashing  GREEN……. One flash every two seconds…
   Each time a key is pushed the RED/GREEN LED flashes one time GREEN and is then off… (if another key is not pressed in 5 seconds….Lock the KEYPAD)
   After the correct four digits and the enter key, the RED/GREEN LED  Flashes 4 times and stays on GREEN

Here is what we have so far (very hodge podge coding, brace yourself)


Code: [Select]


int i, k, pwcount=0;
char password[] = "1342", entry[10];
int ledGreen = 9;
int ledRed = 10;

void setup()
{
  Serial.begin(9600);
 
for(i=2; i<=5; i++)
pinMode(i, INPUT);
  for(i=6; i<=9; i++)
pinMode(i, OUTPUT);
  pinMode(ledGreen, OUTPUT);
pinMode(ledRed, OUTPUT);
}

void loop()
{
 
  for(i=6; i<=8; i++){
  reset();
  digitalWrite(i, HIGH);
  if(digitalRead(2)==HIGH && i==6){
    blinker();
    entry[pwcount] = '1';
    pwcount++;
   delay(300);
  Serial.print('1');
  }
  if(digitalRead(3)==HIGH && i==6){
    blinker();
    entry[pwcount] = '4';
    pwcount++;
   delay(300);
  Serial.print('4');
  }
  if(digitalRead(4)==HIGH && i==6){
    blinker();
    entry[pwcount] = '7';
    pwcount++;
   delay(300);
  Serial.print('7');
  } 
   if(digitalRead(5)==HIGH && i==6){
     blinker();
    entry[pwcount] = '*';
    pwcount++;
   delay(300);
  Serial.print('*');
  }
 
   if(digitalRead(2)==HIGH && i==7){
     blinker();
    entry[pwcount] = '2';
    pwcount++;
   delay(300);
  Serial.print('2');
  }
  if(digitalRead(3)==HIGH && i==7){
    blinker();
    entry[pwcount] = '5';
    pwcount++;
   delay(300);
  Serial.print('5');
  }
  if(digitalRead(4)==HIGH && i==7){
    blinker();
    entry[pwcount] = '8';
    pwcount++;
   delay(300);
  Serial.print('8');
  } 
   if(digitalRead(5)==HIGH && i==7){
     blinker();
   entry[pwcount] = '0';
    pwcount++;
   delay(300);
  Serial.print('0');
  }
 
    if(digitalRead(2)==HIGH && i==8){
      blinker();
    entry[pwcount] = '3';
    pwcount++;
   delay(300);
  Serial.print('3');
  }
  if(digitalRead(3)==HIGH && i==8){
    blinker();
   entry[pwcount] = '6';
    pwcount++;
   delay(300);
  Serial.print('6');
  }
  if(digitalRead(4)==HIGH && i==8){
    blinker();
   entry[pwcount] = '9';
    pwcount++;
   delay(300);
  Serial.print('9');
  } 
   if(digitalRead(5)==HIGH && i==8){
    blinker();
   delay(300);
  Serial.println('#');
  pwcount=0;
  for(k=0; k<=4; k++){
   if(k==4){
   Serial.println("Access Granted");
   digitalWrite(ledGreen, HIGH);
   delay(500);
   digitalWrite(ledGreen, LOW);
   delay(500);
   digitalWrite(ledGreen, HIGH);
   delay(500);
   digitalWrite(ledGreen, LOW);
   delay(500);
   digitalWrite(ledGreen, HIGH);
   delay(500);
   digitalWrite(ledGreen, LOW);
   delay(500);
   digitalWrite(ledGreen, HIGH);
   delay(500);
   digitalWrite(ledGreen, LOW);
   delay(500);
   digitalWrite(ledGreen, HIGH);
   break;
   }
   if(password[k] != entry[k]){
     Serial.println("Denied");
     digitalWrite(ledRed, HIGH);
     delay (500);
     digitalWrite(ledRed, LOW);
     delay(500);
     digitalWrite(ledRed, HIGH);
     delay (500);
     digitalWrite(ledRed, LOW);
     delay(500);
     digitalWrite(ledRed, HIGH);
     delay (500);
     digitalWrite(ledRed, LOW);
     delay(500);
     digitalWrite(ledRed, HIGH);
     delay (500);
     digitalWrite(ledRed, LOW);
     delay(500);
     digitalWrite(ledRed, HIGH);
     break;
   }
  }
  for(k=0; k<10; k++)
  entry[k]=0;
  } 
}}

void reset(){
   int j;
   for(j=6; j<=8; j++)
   digitalWrite(j, LOW);
}

void blinker(){
  digitalWrite(ledGreen, HIGH);
  delay(20);
  digitalWrite(ledGreen, LOW);
 
}


Nick Gammon

Code: [Select]

          digitalWrite(ledRed, HIGH);
          delay (500);
          digitalWrite(ledRed, LOW);
          delay(500);
          digitalWrite(ledRed, HIGH);
          delay (500);
          digitalWrite(ledRed, LOW);
          delay(500);
          digitalWrite(ledRed, HIGH);
          delay (500);
          digitalWrite(ledRed, LOW);
          delay(500);
          digitalWrite(ledRed, HIGH);
          delay (500);
          digitalWrite(ledRed, LOW);
          delay(500);
          digitalWrite(ledRed, HIGH);


Better read up on how to make a loop.
http://www.gammon.com.au/electronics

SpecialTopix

Sorry, we are very very very new and are attempting to stumble our way through this until we fall flat on our faces with some wisdom.

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up