본문 바로가기
  • test
62x32 LED MATRIX 예제/이모티콘 벽에 공 튀기기

[62x32 LED 매트릭스 예제] smileMove

by 혜민우진아빠 2021. 1. 12.

예제의 결과물

 

 

준비물 & 결선 & 세팅하기

아래 링크를 참고해서 준비해주세요.

[62x32 LED 매트릭스 세팅]

 

 

* 준비물 구입 링크

https://smartstore.naver.com/frontiers/products/5380911083%EF%BB%BF

 

스마트폰제어 LED 간판 오픈 입구 전광판 아트사인 부동산 전광판 영업중 개업선물 카페 식당 :

스마트폰과 블루투스 연결을 통해 글자와 이미지를 마음대로 변경

smartstore.naver.com

 

소스코드 다운

iotfrontiers/popsign_examples (github.com)

 

GitHub - iotfrontiers/popsign_examples

Contribute to iotfrontiers/popsign_examples development by creating an account on GitHub.

github.com

위 링크에 들어가셔서 연두색의 Code 버튼을 누르시고

Download ZIP 버튼을 누르면 전체 예제 파일을 다운 받을 수 있습니다.

 

업로드 준비

① 파일 - 열기 항목을 눌러서 현재 진행하고 있는 예제의 ino파일을 선택합니다.

 

 보드와 PC를 USB C타입 케이블로 연결합니다.

 

 장치관리자에서 보드가 연결된 포트를 확인합니다. USB-SERIAL-CH340 이라는 이름으로 표시되어 있습니다.

 위에서 확인한 포트번호를 IDE에 설정합니다

 ESP-32 Dev Module 보드를 선택합니다.

 

⑥ 업로드 준비가 다 되었습니다. 업로드 버튼을 눌러서 업로드 할 수 있습니다.

 

smileMove 소스코드

// RGB Panel GFX Demo example for 64x32 panel

#include <RGBmatrixPanel.h>
#include "smileytongue24.h"

#include <Adafruit_GFX.h>   // Core graphics library
#include <P3RGB64x32MatrixPanel.h>

P3RGB64x32MatrixPanel *matrix = new P3RGB64x32MatrixPanel(25, 26, 27, 21, 22, 0, 15, 32, 33, 12, 5, 23, 4);

// Define matrix width and height.
#define mw 64
#define mh 32

// This could also be defined as matrix->color(255,0,0) but those defines
// are meant to work for Adafruit::GFX backends that are lacking color()

static const uint16_t PROGMEM
    //multicolor smiley face RGB_bmp
    RGB_bmp[64] = {
        0x000, 0x000, 0x00F, 0x00F, 0x00F, 0x00F, 0x000, 0x000,
        0x000, 0x00F, 0x000, 0x000, 0x000, 0x000, 0x00F, 0x000,
        0x00F, 0x000, 0xF00, 0x000, 0x000, 0xF00, 0x000, 0x00F,
        0x00F, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x00F,
        0x00F, 0x000, 0x0F0, 0x000, 0x000, 0x0F0, 0x000, 0x00F,
        0x00F, 0x000, 0x000, 0x0F4, 0x0F3, 0x000, 0x000, 0x00F,
        0x000, 0x00F, 0x000, 0x000, 0x000, 0x000, 0x00F, 0x000,
        0x000, 0x000, 0x00F, 0x00F, 0x00F, 0x00F, 0x000, 0x000, 
};
// Convert a BGR 4/4/4 bitmap to RGB 5/6/5 used by Adafruit_GFX
void fixdrawRGBBitmap(int16_t x, int16_t y, const uint16_t *bitmap, int16_t w, int16_t h) {
    uint16_t RGB_bmp_fixed[w * h];
    for (uint16_t pixel=0; pixel<w*h; pixel++) {
        uint8_t r,g,b;
        uint16_t color = pgm_read_word(bitmap + pixel);

        b = (color & 0xF00) >> 8;
        g = (color & 0x0F0) >> 4;
        r = color & 0x00F;

        // expand from 4/4/4 bits per color to 5/6/5
        b = map(b, 0, 15, 0, 31);
        g = map(g, 0, 15, 0, 63);
        r = map(r, 0, 15, 0, 31);

        RGB_bmp_fixed[pixel] = (r << 11) + (g << 5) + b;
        //Serial.print(" -> ");
        //Serial.println(RGB_bmp_fixed[pixel], HEX);
    }
    matrix->drawRGBBitmap(x, y, RGB_bmp_fixed, w, h);
}

// Scroll within big bitmap so that all if it becomes visible or bounce a
// small one.  If the bitmap is bigger in one dimension and smaller in the
// other one, it will both pan and bounce in the appropriate dimensions.
void display_panOrBounceBitmap (uint8_t bitmapSize) {
    // keep integer math, deal with values 16 times too big
    // start by showing upper left of big bitmap or centering if big display
    int16_t xf = max(0, (mw-bitmapSize)/2) << 4;
    int16_t yf = max(0, (mh-bitmapSize)/2) << 4;
    // scroll speed in 1/16th
    int16_t xfc = 6;
    int16_t yfc = 3;
    // scroll down and right by moving upper left corner off screen
    // more up and left (which means negative numbers)
    int16_t xfdir = -1;
    int16_t yfdir = -1;

    for (uint16_t i=1; i<1000; i++) {
        bool updDir = false;

        // Get actual x/y by dividing by 16.
        int16_t x = xf >> 4;
        int16_t y = yf >> 4;

        matrix->clear();
        // bounce 8x8 tri color smiley face around the screen
        if (bitmapSize == 8) fixdrawRGBBitmap(x, y, RGB_bmp, 8, 8);
        // pan 24x24 pixmap
        if (bitmapSize == 24) matrix->drawRGBBitmap(x, y, (const uint16_t *)bitmap24, bitmapSize, bitmapSize);
        matrix->show();

        // Only pan if the display size is smaller than the pixmap
        if (mw<bitmapSize) {
            xf += xfc*xfdir;
            if (xf >= 0)                      { xfdir = -1; updDir = true ; };
            // we don't go negative past right corner, go back positive
            if (xf <= ((mw-bitmapSize) << 4)) { xfdir = 1;  updDir = true ; };
        }
        if (mh<bitmapSize) {
            yf += yfc*yfdir;
            // we shouldn't display past left corner, reverse direction.
            if (yf >= 0)                      { yfdir = -1; updDir = true ; };
            if (yf <= ((mh-bitmapSize) << 4)) { yfdir = 1;  updDir = true ; };
        }
        // only bounce a pixmap if it's smaller than the display size
        if (mw>bitmapSize) {
            xf += xfc*xfdir;
            // Deal with bouncing off the 'walls'
            if (xf >= (mw-bitmapSize) << 4) { xfdir = -1; updDir = true ; };
            if (xf <= 0)                    { xfdir =  1; updDir = true ; };
        }
        if (mh>bitmapSize) {
            yf += yfc*yfdir;
            if (yf >= (mh-bitmapSize) << 4) { yfdir = -1; updDir = true ; };
            if (yf <= 0)                    { yfdir =  1; updDir = true ; };
        }

       if (updDir) {
            // Add -1, 0 or 1 but bind result to 1 to 1.
            // Let's take 3 is a minimum speed, otherwise it's too slow.
            xfc = constrain(xfc + random(-1, 2), 3, 16);
            yfc = constrain(xfc + random(-1, 2), 3, 16);
        }
        delay(10);
    }
}

void loop() {
    // pan a big pixmap
    display_panOrBounceBitmap(24);
    // bounce around a small one
    display_panOrBounceBitmap(8);
}

void setup() {
    Serial.begin(115200);
    matrix->begin();
    // Test full bright of all LEDs. If brightness is too high
    // for your current limit (i.e. USB), decrease it.
}

 

 

* smileytongue24.h 파일 : 큰 스마일 이모티콘 비트맵

* RGB_bmp[] : 작은 스마일 이모티콘 비트맵

 

* display_panOrBounceBitmap() : 이모티콘을 매트릭스 안에서 이동시킵니다.

* fixdrawRGBBitmap() : 컬러 값을 Adafruit_GFX의 함수에 맞게 변환 시켜줍니다.

* constrainx, a, b ) : 숫자를 특정 범위로 제한합니다

                         (x의 값이 a와 b사이에있따면 x, a보다작다면 a, b보다 크다면 b를 반환합니다.           *

* matrix->drawRGBBitmap() : 비트맵 버퍼에 있는 값을 x, y 좌표에 대하여 출력합니다.  

 

예제에 대한 문의 사항은 댓글로 작성해주시면 빠르게 답변 해드리겠습니다.

댓글