รูปที่ 6.1 แสดงการออกแบบวงจรรับค่า Keypad มาแสดงผลที่ LED 7-Segment |
#include "LedControl.h"
#include "Keypad.h"
char keys[4][4]={
{'7','8','9','A'},
{'4','5','6','B'},
{'1','2','3','C'},
{'E','0','F','D'}};
byte rowPins[] = {7,6,5,4};
byte colPins[] = {3,2,1,0};
Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,4,4);
LedControl lc=LedControl(8,10,9,1);
// Pin 8->DIN, 10->CLK, 9->CS(LOAD), 1 = No.of devices
void setup()
{
lc.shutdown(0,false);
lc.setIntensity(0,5);
lc.clearDisplay(0);
}
void loop()
{
char key = keypad.getKey();
if (key != NO_KEY)
{
lc.setChar(0,0,key,false);
}
}
โค้ดที่ 6.2 (Code Arduino)
#include "LedControl.h"
#include "Keypad.h"
char keys[4][4]={
{'7','8','9','A'},
{'4','5','6','B'},
{'1','2','3','C'},
{'*','0','#','D'}};
byte rowPins[] = {7,6,5,4};
byte colPins[] = {3,2,1,0};
Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,4,4);
LedControl lc=LedControl(8,10,9,1);
// Pin 8->DIN, 10->CLK, 9->CS(LOAD), 1 = No.of devices
int m=7;
void setup()
{
lc.shutdown(0,false);
lc.setIntensity(0,5);
lc.clearDisplay(0);
}
void loop()
{
char key = keypad.getKey();
if (key != NO_KEY)
{
if (m==7)
lc.clearDisplay(0);
lc.setChar(0,m,key,false);
m = m-1;
if (m < 0)
m = 7;
}
}
โค้ดที่ 6.3 (Code Arduino)
#include "LedControl.h"
#include "Keypad.h"
char keys[4][4]={
{'7','8','9','A'},
{'4','5','6','B'},
{'1','2','3','C'},
{'*','0','#','D'}};
byte rowPins[] = {7,6,5,4};
byte colPins[] = {3,2,1,0};
Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,4,4);
LedControl lc=LedControl(8,10,9,1);
// Pin 8->DIN, 10->CLK, 9->CS(LOAD), 1 = No.of devices
int m=3;
char num[4]; //num[0] to num[3]
void setup()
{
lc.shutdown(0,false);
lc.setIntensity(0,5);
lc.clearDisplay(0);
}
void loop()
{
char key = keypad.getKey();
if (key != NO_KEY)
{
if (m==3)
lc.clearDisplay(0);
lc.setChar(0,m,key,false);
num[m]=key;
m = m-1;
if (m < 0)
{
if ((num[3]=='4')&&(num[2]=='0')&&(num[1]=='6')&&(num[0]=='9'))
{
lc.setChar(0,7,'0',false);
lc.setChar(0,6,'P',false);
}
else
{
lc.setChar(0,7,'-',false);
lc.setChar(0,6,'-',false);
}
m = 3;
}
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น