0% found this document useful (0 votes)
68 views5 pages

Ardunio Project

This document defines code for a 4x4 keypad input device connected to an Arduino. It initializes constants for the number of rows and columns of the keypad. A 2D array defines the symbols on each button. Interrupts are attached to digital pins to increment or decrement a counter when those pins change state. A GetNumber function reads keypad input and converts it to a numeric value, and functions are defined to handle the interrupts and check the counter value.

Uploaded by

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

Ardunio Project

This document defines code for a 4x4 keypad input device connected to an Arduino. It initializes constants for the number of rows and columns of the keypad. A 2D array defines the symbols on each button. Interrupts are attached to digital pins to increment or decrement a counter when those pins change state. A GetNumber function reads keypad input and converts it to a numeric value, and functions are defined to handle the interrupts and check the counter value.

Uploaded by

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

#include <Keypad.

h>

const byte ROWS = 4; /* four rows */

const byte COLS = 4; /* four columns */

/* define the symbols on the buttons of the keypads */

char hexaKeys[COLS][ROWS] = {

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

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

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

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

};

byte rowPins[ROWS] = {4, 5, 6, 7}; /* connect to the row pinouts of the keypad */

byte colPins[COLS] = {8, 9, 10, 11}; /* connect to the column pinouts of the keypad */

/* initialize an instance of class NewKeypad */

int v1 = 0;

int v2 = 0;

int v3 = 0;

int v4 = 0;

volatile unsigned int counter = 0;

Keypad kpd = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){

Serial.begin(9600);

pinMode(2, INPUT); // set pin to input


pinMode(3, INPUT); // set pin to input

digitalWrite(2, HIGH); // turn on pullup resistors

digitalWrite(3, HIGH); // turn on pullup resistors

attachInterrupt(0, ai0, RISING);

attachInterrupt(1, ai1, RISING);

void loop()

v1 = GetNumber();

v2 = v1+v1;

Serial.println ();

Serial.println();

Serial.print(v2);

Serial.println();

Serial.println (v3);

int GetNumber()

int num = 0;

char key = kpd.getKey();

while(key != '#')

switch (key)

case NO_KEY:

break;
case '0': case '1': case '2': case '3': case '4':

case '5': case '6': case '7': case '8': case '9':

case 'A': case 'B': case 'C': case 'D':

//lcd.print(key);

Serial.print(key);

num = num * 10 + (key - '0');

break;

case '*':

num = 0;

Serial.println();

Serial.print("Resetted the value");

Serial.print(key);

Serial.println();

key = '#';

counter = 0;

v3 = 0 ;

Serial.print(key);

Serial.print(counter);

//lcd.clear();

break;

key = kpd.getKey();

return num;

void ai0()
{

// ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH

// Check pin 3 to determine the direction

if(digitalRead(3)==LOW)

counter++;

v3 = (counter / 47);

if ( v3 >= v1 && v3 <= v1 )

Serial.println(" Level 1");

Serial.print(v3);

}else{

counter--;

void ai1() {

if(digitalRead(2)==LOW)

counter--;

v3 = (counter / 47 );

else
{

if ( v3 > v1 && v3 <= v2 )

Serial.println(" Level2 ");

Serial.print(v2);

counter++;

You might also like