100% found this document useful (1 vote)
149 views

Arduino Keypad Code

This document describes testing a keypad on an Intel Galileo Gen 2 board. It defines constants for the keypad pins and LED pins, creates a Keypad object to interface with the keypad, and includes functions to handle key presses and update the LED status based on whether the system is locked or unlocked. When the correct password is entered, it will call the updateLEDStatus function to toggle the system status and turn on/off the LEDs accordingly.

Uploaded by

Ella Anaida
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
149 views

Arduino Keypad Code

This document describes testing a keypad on an Intel Galileo Gen 2 board. It defines constants for the keypad pins and LED pins, creates a Keypad object to interface with the keypad, and includes functions to handle key presses and update the LED status based on whether the system is locked or unlocked. When the correct password is entered, it will call the updateLEDStatus function to toggle the system status and turn on/off the LEDs accordingly.

Uploaded by

Ella Anaida
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Intel Galileo Gen 2: testing the keypad

*/

#include <Keypad.h>

enum SYSTEM_STATUS{

LOCKED // 0

UNLOCKED // 1

};

static SYSTEM_STATUS currentStatus = LOCKED;

const String password = "2006";

String input;

const int PIR_sensor = 10 ;

int PIR_value ;

const byte led_white = 11;

const byte led_green = 12;

const byte led_red = 13;

const byte ROWS = 4; // four rows

const byte COLS = 4; // four columns

// Define the Keymap

char keys[ROWS][COLS] = {

{'1','2','3','A'},

{'4','5','6','B'},

{'7','8','9','C'},

{'*','0','#','D'}

};

byte rowPins[ROWS] = {2,3,4,5}; // Connect keypad ROW0, ROW1, ROW2 and ROW3 to the

// Galileo Gen 2 digital pins 2,3,4,5.

byte colPins[ROWS] = {6,7,8,9}; // Connect keypad COL0, COL1, COL2 and COL3 to the Galileo

// Gen 2 digital pins 6, 7, 8, 9.

// Create the Keypad

Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,ROWS,COLS); // Instantiates a

// Keypad object that uses pins 2, 3, 5, 6 as row pins, and 6, 7, 8, 9 as column pins.
// This keypad has 4 rows and 4 columns, resulting in 16 keys.

void setup()

Serial.begin(115200);

pinMode(PIR_sensor, INPUT);

pinMode(led_white, OUTPUT);

pinMode(led_green , OUTPUT);

pinMode(led_white, OUTPUT); // in case there is an LED CONNECTED

digitalWrite(led_white, HIGH); // The default is system locked... so, the LED must be HIGH

digitalWrite(led_green , LOW);

keypad.addEventListener(handleKey); // this is the listener to handle the keys

void loop()

char key = keypad.getKey(); // reading the keyboard

if (key) // if it’s a valid key

if ((key != '#') && (key != '*'))

input += key;

Serial.print("key:");

Serial.println(key);

/* this function is only called when the PIN code typed matches the secret PIN code and inverts the

system logic. It means if the system was LOCKED it will be UNLOCKED and vice versa.

*/
void updateLEDStatus()

if (currentStatus == LOCKED)

currentStatus = UNLOCKED;

Serial.println("SYSTEM UNLOCKED");

digitalWrite(led_white, LOW);// turn OFF the LED white

digitalWrite(led_red, LOW); // turn OFF the LED red

digitalWrite(led_green,LOW); // turn OFF the LED green

else

currentStatus = LOCKED;

Serial.println("SYSTEM LOCKED");

digitalWrite(led_white, HIGH); // turn ON the LED white

digitalWrite(led_red,LOW);

// this function is responsible to handle the keypad events

void handleKey(KeypadEvent key)

switch (keypad.getState())

case PRESSED: digitalWrite(ledPin, !digitalRead(led_white));

delay(500);

digitalWrite(ledPin, !digitalRead(led_white));

if (key == '#') // this is our ENTER

Serial.println(input);

if (input == password)

{
updateLEDStatus();

input = "";

break;

case RELEASED: if (key == '*')

input = ""; // this is our CLEAR

break;

You might also like