Input Score Keypad Interface LED Modul P10
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa digunakan untuk menampilkan nilai atau angka / score ke led modul P10 dengan input keypad matrik 4x4. jadi alat ini untuk memulai menampilkan nilai tekan * pada keypad lalu jika ingin melakukan input nilai baru tekan # untuk clear nilai pada lcd lalu input nilainya. untuk lebih jelasnya berikut adalah koding dan skemanya.
a. Skema
b. Program Arduino IDE
#include <Wire.h>
#include <SPI.h> //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)
#include <DMD.h> //Library DMD yang menyediakan fungsi penampilan teks, gambar dsb
#include <TimerOne.h> //Library peripheral Timer1 untuk menjalankan prosedur pindai panel DMD
#include <Time.h> //Library waktu yang menyediakan tipe data, struktur, dan obyek waktu
#include "Arial_black_16.h"
#include "Arial_Black_16_ISO_8859_1.h"
#include "Arial14.h"
#include "DejaVuSans9.h"
#include "DejaVuSansBold9.h"
#include "DejaVuSansItalic9.h"
#include "Droid_Sans_12.h"
#include "Droid_Sans_16.h"
#include "Mono5x7.h"
#include "SystemFont5x7.h"
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#define WAKTU_TAMPIL_JAM 10 //detik
#define WAKTU_TAMPIL_KALENDAR 5 //detik
#define DISPLAY_COLUMN_COUNT 2
#define DISPLAY_ROW_COUNT 1
#define PIXELS_PER_COLUMN 32
#define PIXELS_PER_ROW 16
DMD dmd(DISPLAY_COLUMN_COUNT, DISPLAY_ROW_COUNT);
unsigned char show = 0;
char lineBuff[20];
char lineBuffx[20];
long dataku = 0;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
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 to the row pinouts of the keypad
byte colPins[COLS] = {A0,A1,A2,A3}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void ScanDMD()
{
dmd.scanDisplayBySPI();
}
void setup(void)
{
dmd.clearScreen( true ); //true is normal (all pixels off), false is negative (all pixels on)
Serial.begin(9600);
lcd.begin();
lcd.noCursor();
lcd.clear();
//initialize TimerOne's interrupt/CPU usage used to scan and refresh the display
Timer1.initialize( 1000 ); //period in microseconds to call ScanDMD. Anything longer than 5000 (5ms) and you can see flicker.
Timer1.attachInterrupt( ScanDMD ); //attach the Timer1 interrupt to ScanDMD which goes to dmd.scanDisplayBySPI()
//clear/init the DMD pixels held in RAM
dmd.clearScreen( true );
}
void loop(void)
{
customKey = customKeypad.getKey();
if(customKey >= '0' && customKey <= '9')
{
dataku = dataku * 10 + (customKey - '0');
lcd.setCursor(0,0);
lcd.print("MASUKKAN SCORE");
lcd.setCursor(8,1);
lcd.print(dataku);
}
if(customKey == '*'){
delay(200);
tampil();
}
if(customKey == '#'){
delay(200);
lcd.clear();
dataku = 0;
}
delay(200);
}
void tampil(){
sprintf(lineBuffx, "%d ", dataku);
dmd.selectFont(DejaVuSans9);
dmd.selectFont(Mono5x7);
dmd.drawString( 33, 0, lineBuffx, strlen(lineBuffx), GRAPHICS_NORMAL);
//tampil();
}
c. VIDEO HASILNYA