본문 바로가기
아두이노

아두이노 8x8 도트 매트릭스

by artra 2017. 4. 30.
반응형

 

연결 방법은 빵판에 8X8 LED를 연결한후 한줄을 digital 9~2 까지

다른한줄을 digital 13~10 , analog A0~A3 까지

코드대로 했는데도 안된다면 반대로 끼워 보세요

 

1. 도트 하나만 켜보기

int row[] = ; // 가로
int col[] = ; // 세로
 
void setup(){
    pinMode(col[7], OUTPUT); // 0 ~ 7 까지 숫자변환시 위치바뀜
    pinMode(row[7], OUTPUT); // 0 ~ 7 까지 숫자변환시 위치바뀜
}
 
void loop(){
  for(int i=0; i < 8; i++){
    digitalWrite(col[i], 0);
    digitalWrite(row[i], 1);
    delay(10);
 
    digitalWrite(col[i], 1);
    digitalWrite(row[i], 0);
    delay(10);
  }
}
cs

*********************************************

2. 1줄 전체 켜키

 

const int row[8= { 2717513161214 };
const int col[8= { 61110315489 };
 
void setup(){
  for(int i = 0; i <8; i ++){
    pinMode(col[i], OUTPUT);
    pinMode(row[i], OUTPUT);
  }
}
 
void loop(){
    digitalWrite(row[3], 1); // row[?] 0~7까지 숫자를 바꾸면됨
}
 
 
cs

*********************************************

 

http://arduino-er.blogspot.kr/2015/02/beating-heart-animation-on-8x8-led.html

하트가 위아래로 움직이는 코드 / 위주소에서 가져옴

 

이중에서 아래 8x8 하트모양의 1, 0 을 바꾸면 그림을 바꿀수도 있습니다.

애니메이션 순서 바꾸는 방법은 영문 순서를 바꾸면 됩니다.

시간 바꾸는 방법은 아래 count 코드쪽에 보일것입니다.

여기 아래부터 붙어서 복 붙해서 업로드하면 됩니다.

 

// 2-dimensional array of row pin numbers:
const int row[8= {
  2717513161214
};
 
// 2-dimensional array of column pin numbers:
const int col[8= {
  61110315489
};
 
// 2-dimensional array of pixels:
int pixels[8][8];
int count = 1000;
int strLen = sizeof(str);
int ptrChar = 0;
char str[] = "FABCDEDCBA"// 애니메이션 순서 바꾸기
 
typedef bool charMapType[8][8];
 
const charMapType charBlank = { // 위 영문 순서의 (char str[] =)F 부분
  {00000000},
  {00000000},
  {00000000},
  {00000000},
  {00000000},
  {00000000},
  {00000000},
  {00000000}
};
 
const charMapType heart0 = { // A파트 부분
  {00000000},
  {00000000},
  {00000000},
  {00000000},
  {00011000},
  {00011000},
  {00000000},
  {00000000}
};
 
const charMapType heart1 = { // B파트 부분
  {00000000},
  {00000000},
  {00000000},
  {00011000},
  {00111100},
  {00111100},
  {00011000},
  {00000000}
};
 
const charMapType heart2 = { // C파트 부분
  {00000000},
  {00000000},
  {01100110},
  {11111111},
  {11111111},
  {01111110},
  {00111100},
  {00011000}
};
 
const charMapType heart3 = { // D파트 부분
  {00000000},
  {01100110},
  {11111111},
  {11111111},
  {01111110},
  {00111100},
  {00011000},
  {00000000}
};
 
const charMapType heart4 = { // E파트 부분
  {01100110},
  {11111111},
  {11111111},
  {01111110},
  {00111100},
  {00011000},
  {00000000},
  {00000000}
};
 
const charMapType *charMap[6= {&heart0, &heart1, &heart2, &heart3, &heart4, &charBlank};
 
void setup() {
  // initialize the I/O pins as outputs
  // iterate over the pins:
  for (int thisPin = 0; thisPin < 8; thisPin++) {
    // initialize the output pins:
    pinMode(col[thisPin], OUTPUT);
    pinMode(row[thisPin], OUTPUT);
    // take the col pins (i.e. the cathodes) high to ensure that
    // the LEDS are off:
    digitalWrite(col[thisPin], HIGH);
  }
  //setupScreen();
  setupChar();
}
 
void loop() {
  // draw the screen:
  refreshScreen();
 
  if(count-- == 0){
    count = 1000// 속도 바꾸기
    setupChar();
  }
}
 
void setupChar(){
  char c = str[ptrChar];
  int offset = c - 'A';
 
  const charMapType *cMap = charMap[offset];
 
  //charMapType *cMap = &charDummy;
 
  for (int x = 0; x < 8; x++) {
    for (int y = 0; y < 8; y++) {
      bool v = (*cMap)[x][y];
 
      if(v){
        pixels[x][y] = LOW;
      }else{
        pixels[x][y] = HIGH;
      }
    }
  }
 
  ptrChar++;
 
  if(ptrChar>=strLen-1){
    ptrChar = 0;
  }
}
 
 
void refreshScreen() {
  // iterate over the rows (anodes):
  for (int thisRow = 0; thisRow < 8; thisRow++) {
    // take the row pin (anode) high:
    digitalWrite(row[thisRow], HIGH);
    // iterate over the cols (cathodes):
    for (int thisCol = 0; thisCol < 8; thisCol++) {
      // get the state of the current pixel;
      int thisPixel = pixels[thisRow][thisCol];
      // when the row is HIGH and the col is LOW,
      // the LED where they meet turns on:
      digitalWrite(col[thisCol], thisPixel);
      // turn the pixel off:
      if (thisPixel == LOW) {
        digitalWrite(col[thisCol], HIGH);
      }
    }
    // take the row pin low to turn off the whole row:
    digitalWrite(row[thisRow], LOW);
  }
}
cs

*********************************************

int pins[17]= {-1, 5, 4, 3, 2, 16, 17, 18, 19, 13, 12, 11, 10, 9,8, 7, 6};

int rows[8] = ;

int cols[8] = ;

반응형

'아두이노' 카테고리의 다른 글

아두이노 + DC모터 + L298N + 가변저항  (0) 2017.05.23
RGB LED 켜보기  (0) 2017.05.15
아두이노 (5) 사운드  (0) 2017.04.27
왜? 아두이노 해야해?  (0) 2017.04.19
아두이노 그림, 그리는 사이트  (0) 2017.04.19

댓글