Skip to content

Instantly share code, notes, and snippets.

@Parsiuk
Created October 29, 2019 12:08
Show Gist options
  • Save Parsiuk/e629720e6980b6bb3214c13c57d7fe5b to your computer and use it in GitHub Desktop.
Save Parsiuk/e629720e6980b6bb3214c13c57d7fe5b to your computer and use it in GitHub Desktop.
#include <Keypad.h>
int ledPin = 13;
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{
'1', '2', '3' }
,
{
'4', '5', '6' }
,
{
'7', '8', '9' }
,
{
'*', '0', '#' }
};
byte rowPins[ROWS] = {
2, 3, 4, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
6, 7, 8}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); // sets the LED off
}
void loop()
{
char pressedKey = keypad.waitForKey();
switch (pressedKey) {
case '*':
//do shit
break;
case '1':
blink(1);
break;
case '2':
blink(2);
break;
case '3':
blink(3);
break;
case '4':
blink(4);
break;
case '5':
blink(5);
break;
case '6':
blink(6);
break;
case '7':
blink(7);
break;
case '8':
blink(8);
break;
case '9':
blink(9);
break;
default:
//do shit
break;
}
}
void blink(int times)
{
while (times>0)
{
delay(250); // waits for a second
digitalWrite(ledPin, HIGH); // sets the LED on
delay(500); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
times--;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment