반응형
TTP229라는 아두이노 키패드 이다.
소스코드가 간단해서 쉽게 할 수 있을것 같다.
특징이라면 가격이 저렴하고 정전식, 손가락이 큰 사람이 누르기는 주위해야 할 정도.
소스 코드를 어떻게 수정하냐에 따라 동시 버턴도 가능하다.
본인은 동시 버턴은 불필요하고 16Key 까지 입력을 위해서 아래 3번 모듈을 쇼트 시켰다.
나름 쇼트하는 방식으로 여러가지 모드를 구현하게 만들수 있는것 같다.
아직까지는 그렇게 까지는 필요 없어서 단순하게 접근했다.
연결방식은 간단하지만 설명을 하자면 4핀 연결이고 전원, GND, SCL, SDO 연결이다.
SCL이 있다고 I2C연결은 아니다.
/* Define the digital pins used for the clock and data */
#define SCL_PIN 5
#define SDO_PIN 4
/* Used to store the key state */
byte Key;
void setup()
{
/* Initialise the serial interface */
Serial.begin(115200);
/* Configure the clock and data pins */
pinMode(SCL_PIN, OUTPUT);
pinMode(SDO_PIN, INPUT);
}
/* Main program */
void loop()
{
/* Read the current state of the keypad */
Key = Read_Keypad();
if(Key < 17 && Key > 0)
{static byte oldKey;
/* If a key has been pressed output it to the serial port */
if (oldKey != Key && Key)
{
Serial.println(Key);
oldKey = Key;
delay(100);
}
}
/* Wait a little before reading again
so not to flood the serial port*/
delay(100);
}
/* Read the state of the keypad */
byte Read_Keypad(void)
{
byte Count;
byte Key_State = 0;
/* Pulse the clock pin 8 times (one for each key of the keypad)
and read the state of the data pin on each pulse */
for(Count = 1; Count <= 16; Count++)
{
digitalWrite(SCL_PIN, LOW);
/* If the data pin is low (active low mode) then store the
current key number */
if (!digitalRead(SDO_PIN))
{
Key_State = Count;
break;
}
digitalWrite(SCL_PIN, HIGH);
}
return Key_State;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
'아두이노' 카테고리의 다른 글
아두이노와 달력 - #1 (0) | 2020.03.01 |
---|---|
아두이노 Serial MP3 모듈 -#4 (0) | 2020.02.23 |
아두이노 버턴과 키패드- #1 (0) | 2020.02.23 |
아두이노 Serial MP3 모듈 -#3 (2) | 2020.02.06 |
아두이노 Serial MP3 모듈 -#2 (0) | 2020.02.06 |
댓글