0% found this document useful (0 votes)
10 views2 pages

Keypad Timmer

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Keypad Timmer

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <Keypad.

h>
#define LED_DATA 5 //Pin connected to DS of 74HC595
#define LED_CLK 4 //Pin connected to SH_CP of 74HC595
#define LED_LATCH 18 //Pin connected to ST_CP of 74HC595
#define BEEPER 2

const uint8_t ROWS = 4;


// define numero de columnas
const uint8_t COLS = 4;
// define la distribucion de teclas
char keys[ROWS][COLS] = {
{ 6, 91, 79, 119 },
{ 102, 109, 125, 124 },
{ 7, 127, 111, 88 },
{ 113, 63, 249, 94 }
};
// pines correspondientes a las filas
uint8_t colPins[COLS] = { 13, 12, 24, 27 };
// pines correspondientes a las columnas
uint8_t rowPins[ROWS] = { 26, 25, 33, 32 };
// crea objeto con los prametros creados previamente
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

//int secondsleft = 60;

void setup() {
pinMode(LED_LATCH, OUTPUT);
pinMode(LED_CLK, OUTPUT);
pinMode(LED_DATA, OUTPUT);
pinMode(BEEPER, OUTPUT);
}

void loop() {
char secondsleft = keypad.getKey();
while(secondsleft>0){
secondsleft -= 1;
seconds2LED(secondsleft);
secondsleft==0 ? theEnd() : beep();
}
}

void beep(){
digitalWrite(BEEPER,HIGH);
delay(40);
digitalWrite(BEEPER,LOW);
delay(960);
}

void theEnd(){
digitalWrite(BEEPER,HIGH);
delay(2000);
digitalWrite(BEEPER,LOW);
}

int getDigit(int number, int position){


int result = ((int)(number / pow(double(10),double(position))) % 10);
return result;
}
// 3 2 1 0
//[1][0][1][3]
void seconds2LED(int seconds){
int lednrcode[] = {0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xb6, 0xBE, 0xE0, 0xFE, 0xF6};
digitalWrite(LED_LATCH, LOW);
for(int digit=0;digit<4;digit++){
int num = getDigit(seconds,digit);
shiftOut(LED_DATA, LED_CLK, LSBFIRST, lednrcode[num]);
}
digitalWrite(LED_LATCH, HIGH);
}

You might also like