BASIC4MCU | 질문게시판 | 아두이노 도트 매트릭스 코딩
페이지 정보
작성자 끼룩 작성일2022-06-13 22:29 조회884회 댓글1건본문
안녕하십니까! 혼자 아두이노 코딩을 공부하고 있는 학생입니다.
1088AS 도트 매트릭스와 5개의 스위치를 이용하여 LED 점의 이동을 통해 오목 게임을 만들어보고 시도하는 중입니다. 파일에 만들고 있는 아두이노 사진을 첨부하였습니다.
아래가 지금까지 진행한 코딩입니다. 하지만, 여기에서 LED 점의 이동은 코딩할 수 있었지만 그 이후 LED 점을 고정시키고 다음의 새로운 점을 생성하여 점을 이동시키는 것에 어려움이 있어 질문을 드립니다.
const int yPins[] = { 2, 3, 4, 5, 6, 7, 8, 9};
// C8, C7, C6, C5, C4, C3, C2, C1
const int xPins[] = { 10,11,12,15,16,17,18,19};
// R8, R7, R6, R5, R4, R3, R2, R1
const int inputPinL1 = 0;
const int inputPinR1 = 1;
const int inputPinU1 = 14;
const int inputPinD1 = 15;
const int inputPinF1 = 16;
int X1 = 0;
int Y1 = 0;
int X2 = 0;
int Y2 = 0;
void setup() {
pinMode(inputPinL1, INPUT_PULLUP);
pinMode(inputPinR1, INPUT_PULLUP);
pinMode(inputPinU1, INPUT_PULLUP);
pinMode(inputPinD1, INPUT_PULLUP);
pinMode(inputPinF1, INPUT_PULLUP);
for (int i = 0; i < 8; i++)
{
pinMode(yPins[i], OUTPUT);
pinMode(xPins[i], OUTPUT);
digitalWrite(yPins[i],LOW);
digitalWrite(xPins[i],HIGH);
}
}
void loop() {
int swInputL1 = digitalRead(inputPinL1);
int swInputR1 = digitalRead(inputPinR1);
int swInputU1 = digitalRead(inputPinU1);
int swInputD1 = digitalRead(inputPinD1);
int swInputF1 = digitalRead(inputPinF1);
if(swInputR1==LOW) {
X1++;
expression1out(X1-1,Y1);
expression1(X1,Y1);
}
if (X1==8) {
X1=0;
}
if(swInputL1==LOW) {
X1--;
expression1out(X1+1,Y1);
expression1(X1,Y1);
}
if(swInputU1==LOW) {
Y1++;
expression1out(X1,Y1-1);
expression1(X1,Y1);
}
if (Y1==8) {
Y1=0;
}
if(swInputD1==LOW) {
Y1--;
expression1out(X1,Y1+1);
expression1(X1,Y1);
}
if (Y1==8) {
Y1=0;
}
if(swInputF1==LOW) {
expression2(X1,0);
}
}
void expression1(int X1,int Y1)
{
digitalWrite(yPins[Y1],HIGH);
digitalWrite(xPins[X1],LOW);
delay(100);
}
void expression2(int X2,int Y2)
{
digitalWrite(yPins[Y2],HIGH);
digitalWrite(xPins[X2],LOW);
delay(100);
}
void expression1out(int X1,int Y1)
{
digitalWrite(yPins[Y1],LOW);
digitalWrite(xPins[X1],HIGH);
delay(100);
}
댓글 1
조회수 884master님의 댓글
master 작성일
단색으로 두 사람의 오목을 구분 할 수 있을까요?
2색 이상의 도트매트릭스를 사용하셔야 할 듯
//
char omok[64]={0,}; // 오목배열 초기화
char x=0,y=0; // 커서위치 // 다음사람 시작은 마지막 커서 위치에서 시작
커서위치는 깜박거리고, 이미 알이 배치된 자리라면 색상을 변경하면서 깜박거림, 알이 배치되지 않은 자리라면 본인 색상이 깜박거림
커서를 이동해서 엔터키를 눌러서 자리를 고정하는 경우
0이 아니라면(해당 자리에 알이 배치되지 않은 경우)
본인 칼라를 저장함
//
매트릭스는 배열의 칼라값을 읽어서 출력하면 됩니다.