BASIC4MCU | 질문게시판 | 도트 매트릭스와 블루투스 모듈
페이지 정보
작성자 진혁잉 작성일2020-06-20 15:59 조회6,266회 댓글2건본문
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(18, 19);
enum { R5=1,R7,C2,C3,R8,C5,R6,R3,R1,C4,C6,R4,C1,R2,C7,C8 };
const unsigned int pins[1+16] = {
-1, 10,11,12,13,14,15,16,17, 2,3,4,5,6,7,8,9
};
const unsigned int R[1+8] = { -1, R1, R2, R3, R4, R5, R6, R7, R8 };
const unsigned int C[1+8] = { -1, C1, C2, C3, C4, C5, C6, C7, C8 };
const unsigned int ON[1+8][1+8] = {
{-1, -1, -1, -1, -1, -1, -1, -1},
{-1, 1, 1, 1, 1, 1, 1, 1, 1},
{-1, 1, 1, 1, 1, 1, 1, 1, 1},
{-1, 1, 1, 1, 1, 1, 1, 1, 1},
{-1, 1, 1, 1, 1, 1, 1, 1, 1},
{-1, 1, 1, 1, 1, 1, 1, 1, 1},
{-1, 1, 1, 1, 1, 1, 1, 1, 1},
{-1, 1, 1, 1, 1, 1, 1, 1, 1},
{-1, 1, 1, 1, 1, 1, 1, 1, 1},
};
const unsigned int OFF[1+8][1+8] = {
{-1, -1, -1, -1, -1, -1, -1, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0},
{-1, 0, 0, 0, 0, 0, 0, 0, 0},
{-1, 0, 0, 0, 0, 0, 0, 0, 0},
{-1, 0, 0, 0, 0, 0, 0, 0, 0},
{-1, 0, 0, 0, 0, 0, 0, 0, 0},
{-1, 0, 0, 0, 0, 0, 0, 0, 0},
{-1, 0, 0, 0, 0, 0, 0, 0, 0},
{-1, 0, 0, 0, 0, 0, 0, 0, 0},
};
const unsigned int heart[1+8][1+8] = {
{-1, -1, -1, -1, -1, -1, -1, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0},
{-1, 0, 1, 1, 0, 0, 1, 1, 0},
{-1, 1, 1, 1, 1, 1, 1, 1, 1},
{-1, 1, 1, 1, 1, 1, 1, 1, 1},
{-1, 0, 1, 1, 1, 1, 1, 1, 0},
{-1, 0, 0, 1, 1, 1, 1, 0, 0},
{-1, 0, 0, 0, 1, 1, 0, 0, 0},
{-1, 0, 0, 0, 0, 0, 0, 0, 0},
};
const unsigned int heart_small[1+8][1+8] = {
{-1, -1, -1, -1, -1, -1, -1, -1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0},
{-1, 0, 0, 0, 0, 0, 0, 0, 0},
{-1, 0, 0, 1, 0, 0, 1, 0, 0},
{-1, 0, 1, 1, 1, 1, 1, 1, 0},
{-1, 0, 0, 1, 1, 1, 1, 0, 0},
{-1, 0, 0, 0, 1, 1, 0, 0, 0},
{-1, 0, 0, 0, 0, 0, 0, 0, 0},
{-1, 0, 0, 0, 0, 0, 0, 0, 0},
};
void dot_matrix_init() {
// 도트 매트릭스 핀 초기화
for(int n=1;n<=8;n++) {
pinMode(pins[R[n]], OUTPUT);
pinMode(pins[C[n]], OUTPUT);
}
// 도트 매트릭스 끄기
for(int n=1;n<=8;n++) {
digitalWrite(pins[R[n]], HIGH);
digitalWrite(pins[C[n]], HIGH);
}
}
void dot_matrix_draw(const unsigned int image[1+8][1+8]) {
// 도트 매트릭스 그리기
for(int n=1;n<=8;n++) {
// 열을 꺼준다.
if(n>1) digitalWrite(pins[R[n-1]], HIGH);
if(n==1) digitalWrite(pins[R[8]], HIGH);
// 행을 켤 준비를 한다.
for(int m=1;m<=8;m++) {
if(image[n][m] == 1)
digitalWrite(pins[C[m]], HIGH);
else digitalWrite(pins[C[m]], LOW);
}
// 열을 켜준다.
for(int m=1;m<=8;m++) {
if(image[n][m] == 1) {
digitalWrite(pins[R[n]], LOW);
}
}
delay(1);
}
}
void setup() {
BTSerial.begin(9600);
dot_matrix_init();
}
void loop() {
if(BTSerial.available())
{
char bt;
bt = BTSerial.read();
if(bt == 'a')
dot_matrix_draw(heart);
if(bt == 'b')
dot_matrix_draw(heart_small);
}
여기서 a를 입력했을 때 하트가 1회만 그려지는 게 아닌 계속해서 나오게 하고 시펑요 ㅜㅜ
}
댓글 2
조회수 6,266master님의 댓글
master 작성일
char bt=0
//
void loop(){
if(BTSerial.available()){
bt=BTSerial.read();
}
if(bt=='a')dot_matrix_draw(heart);
if(bt=='b')dot_matrix_draw(heart_small);
}
진혁잉님의 댓글
진혁잉
감사합니다!