// LABORATORY ACTIVITY NO. 9 - ARDUINO KEYPAD AND OLED
// EMBEDDED SYSTEMS GROUP NO. 1
// Dela Cruz, Hannah Mae B.
// Dimailig, Ariel S.
// Marcelo, Jonard I.
// Pagtalunan, Jonas D.
// Rea, Allen Nhicole M.
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h> //library of OLED display
#include <Keypad.h> //library of membrane keypad
#define screenWidth 128 //define width of OLED
#define screenHeight 64 //define height of OLED
#define res 4
Adafruit_SSD1306 display(screenWidth, screenHeight, &Wire, res);
//keypad
const uint8_t noOfRows = 4; //define number of rows
const uint8_t noOfCols = 4; //define number of columns
//declare the keys of the keypad
char keys[noOfCols][noOfCols] =
{
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t columnPin[noOfCols] = { 9, 8, 7, 6 }; //define column pins
uint8_t rowPin[noOfRows] = { 13, 12, 11, 10 }; //define row pins
Keypad keypad = Keypad(makeKeymap(keys), rowPin,
columnPin, noOfRows, noOfCols);
void setup()
{
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); //Loop
}
Serial.begin(9600);
}
void loop()
{
char key = keypad.getKey();
if (key)
{
display.clearDisplay();
display.setTextSize(5);
display.setTextColor(WHITE);
display.setCursor(0, 15);
display.println(key);
display.setCursor(50, 15);
display.println(key);
display.setCursor(98, 15);
display.println(key);
display.display();
}
}