[Noisebridge-discuss] the fucking doorkeypad is finished

Jake jake at spaz.org
Wed Feb 15 18:05:33 PST 2012


well, almost finished.  I still have to screw and hotglue it all together, 
and then attach it to the outside gate.

But all the materials are gathered, the prototype worked perfectly, and 
the software (for the doorkeypad) is finished.

now it's time for someone ELSE to design the keycode lookup system, and 
the goodlist/badlist and logs and whatever else.  Run it on minotaur.

the doorkeypad talks through a serial port.  It sends the ASCII of the 
button that was pressed;  01234567890*# do whatever you want with those 
characters.  The keypad is debounced and has no repeat; the character is 
sent when the key is pressed down.

If you send a character to the doorkeypad, you can send R to light up the 
Red LED for a second, G to light up the Green LED for a second, H to make 
a Happy sound for 500mS and S to make a Sad sound for 500mS.  If you want 
to make weird morse code you can send a Q to Quiet a sound before it's 
finished, and of course all these details can be easily adjusted, for 
example if we want to use an ultraviolet LED and an infrared LED instead 
of red and green.

the materials include the front of an old COCOT payphone (NO HANDSET) to 
protect the metal keys of the keypad.  an Atmega168 does the thinking, and 
a MAX232 adjusts the serial voltages up to proper RS232 for the long run 
to minotaur.  A cat5 cable with RJ45 plugs on the end will do the job.
It is powered by 5V injected to the cable at minotaur.

A second keypad will be built to go inside the space at the top of the 
stairs, and eventually it will be necessary to enter a code to buzz the 
door at all (as opposed to just pressing the DOOR button).

So make sure your code can run multiple instances, since there will be two 
keypads.

-jake

doorkeypad2.pde

int col1 = 6;  // amarillo
int col2 = 7;  // verde
int col3 = 8;  // anaranjado
int row1 = 9;  // azul
int row2 = 10; // rojo
int row3 = 11; // negro
int row4 = 12; // blanco
int redpin = 2;
int greenpin = 13;
int noisepin = 3;
int sadtone = 200;
int sadtime = 500;
int happytone = 1000;
int happytime = 500;

// int one,two,three,four,five,six,seven,eight,nine,zero,star,pound;
int butt[13] = {
   0,0,0,0,0,0,0,0,0,0,0,0};
char chars[13] = {
   'X','1','2','3','4','5','6','7','8','9','0','*','#'};

// THIS PROGRAM IS FOR A TWELVE-BUTTON NUMERIC KEYPAD FOR SECURE OPENING
// OF THE GATE AT A HACKERSPACE OR ANY OTHER PLACE.
// IT SENDS THE CHARACTER PRESSED THROUGH THE SERIAL PORT,
// AND IT CAN RECIEVE COMMANDS TO TURN ON LEDS OR MAKE BEEPY NOISES.

unsigned long lastime = 0;
unsigned long redlastime = 0;
unsigned long greenlastime = 0;
unsigned long noiselastime = 0;
unsigned long nowtime;
unsigned long debouncetime = 250;  // milliseconds between buttonpresses
unsigned long redtime = 1000;
unsigned long greentime = 1000;
unsigned long noisetime = 1000;
int lastbutt = 0;

void setup()
{
   pinMode(col1,OUTPUT);
   pinMode(col2,OUTPUT);
   pinMode(col3,OUTPUT);
   pinMode(row1,INPUT);
   pinMode(row2,INPUT);
   pinMode(row3,INPUT);
   pinMode(row3,INPUT);
   digitalWrite(row1,HIGH);
   digitalWrite(row2,HIGH);
   digitalWrite(row3,HIGH);
   digitalWrite(row4,HIGH);
   Serial.begin(9600);
   pinMode(redpin,OUTPUT);
   pinMode(greenpin,OUTPUT);
   pinMode(noisepin,OUTPUT);
}

void loop()
{
   digitalWrite(col1,LOW);
   digitalWrite(col2,HIGH);
   digitalWrite(col3,HIGH);
   butt[1] = !digitalRead(row1);
   butt[4] = !digitalRead(row2);
   butt[7] = !digitalRead(row3);
   butt[11] = !digitalRead(row4);

   digitalWrite(col1,HIGH);
   digitalWrite(col2,LOW);
   digitalWrite(col3,HIGH);
   butt[2] = !digitalRead(row1);
   butt[5] = !digitalRead(row2);
   butt[8] = !digitalRead(row3);
   butt[10] = !digitalRead(row4);

   digitalWrite(col1,HIGH);
   digitalWrite(col2,HIGH);
   digitalWrite(col3,LOW);
   butt[3] = !digitalRead(row1);
   butt[6] = !digitalRead(row2);
   butt[9] = !digitalRead(row3);
   butt[12] = !digitalRead(row4);

   int tempbutt = oneisdown();
   nowtime = millis();
   if (tempbutt != 0) {
     if (tempbutt != lastbutt)
       if  (nowtime - lastime > debouncetime) {
         Serial.print(chars[tempbutt]);
         lastbutt = tempbutt;
         lastime = nowtime;
       }
   }
   else
     lastbutt = tempbutt;
   handleserial();
}

int oneisdown() {
   int prest,sum = 0;
   for (int i = 1; i < 13; i++) {
     sum += butt[i];
     if (butt[i])
       prest = i;
   }
   if (sum == 1)
     return prest;
   else return 0;
}

void handleserial() {
   if (Serial.available() > 0) {
     switch (Serial.read()) {
     case 'R':    // R is for Red LED
//      Serial.println("RED");
       digitalWrite(redpin,HIGH);
       redlastime = nowtime;
       break;
     case 'G':    // G is for Green LED
//      Serial.println("GREEN");
       digitalWrite(greenpin,HIGH);
       greenlastime = nowtime;
       break;
     case 'H':    // your hand is a few inches from the sensor
       tone(3, happytone, happytime);
//      Serial.println("HAPPY");
       break;
     case 'S':    // your hand is nowhere near the sensor
       tone(3, sadtone, sadtime);
//      Serial.println("SAD");
       break;
     case 'Q':    // your hand is nowhere near the sensor
       noTone(3);
//      Serial.println("QUIET");
       break;
     }
   }
   if (nowtime - redlastime > redtime) digitalWrite(redpin,LOW);
   if (nowtime - greenlastime > greentime) digitalWrite(greenpin,LOW);
//  if (nowtime - noiselastime > noisetime) digitalWrite(noisepin,LOW);
}










More information about the Noisebridge-discuss mailing list