본문 바로가기
  • test
62x32 LED MATRIX 예제/움직임이 변하는 네모

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

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

예제의 결과물

 

 

준비물 & 결선 & 세팅하기

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

[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 보드를 선택합니다.

 

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

 

changeSquare 소스코드

// RGB Panel GFX Demo example for 16x32 panel
// By Marc MERLIN <marc_soft@merlins.org>
// Contains code (c) Adafruit, license BSD

// WILL NOT FIT on ARDUINO UNO -- requires a Mega, M0 or M4 board

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

// Most of the signal pins are configurable, but the CLK pin has some
// special constraints.  On 8-bit AVR boards it must be on PORTB...
// Pin 11 works on the Arduino Mega.  On 32-bit SAMD boards it must be
// on the same PORT as the RGB data pins (D2-D7)...
// Pin 8 works on the Adafruit Metro M0 or Arduino Zero,
// Pin A4 works on the Adafruit Metro M4 (if using the Adafruit RGB
// Matrix Shield, cut trace between CLK pads and run a wire to A4).


#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);

// Panel Matrix doesn't fully work like Neomatrix (which I originally
// wrote this demo for), so map a few calls to be compatible. The rest
// comes from Adafruit_GFX and works the same on both backends.
#define setBrightness(x) fillScreen(0) // no-op, no brightness on this board
#define clear()          fillScreen(0)
#define show()           swapBuffer()
#define Color(x,y,z)     color444(x/16,y/16,z/16)

// 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()
#define LED_BLACK           0

#define LED_RED_VERYLOW    (3 <<  11)
#define LED_RED_LOW        (7 <<  11)
#define LED_RED_MEDIUM     (15 << 11)
#define LED_RED_HIGH       (31 << 11)

#define LED_GREEN_VERYLOW  (1 <<  5)
#define LED_GREEN_LOW      (15 << 5)
#define LED_GREEN_MEDIUM   (31 << 5)
#define LED_GREEN_HIGH     (63 << 5)

#define LED_BLUE_VERYLOW     3
#define LED_BLUE_LOW         7
#define LED_BLUE_MEDIUM     15
#define LED_BLUE_HIGH       31

#define LED_ORANGE_VERYLOW (LED_RED_VERYLOW + LED_GREEN_VERYLOW)
#define LED_ORANGE_LOW     (LED_RED_LOW     + LED_GREEN_LOW)
#define LED_ORANGE_MEDIUM  (LED_RED_MEDIUM  + LED_GREEN_MEDIUM)
#define LED_ORANGE_HIGH    (LED_RED_HIGH    + LED_GREEN_HIGH)

#define LED_PURPLE_VERYLOW (LED_RED_VERYLOW + LED_BLUE_VERYLOW)
#define LED_PURPLE_LOW     (LED_RED_LOW     + LED_BLUE_LOW)
#define LED_PURPLE_MEDIUM  (LED_RED_MEDIUM  + LED_BLUE_MEDIUM)
#define LED_PURPLE_HIGH    (LED_RED_HIGH    + LED_BLUE_HIGH)

#define LED_CYAN_VERYLOW   (LED_GREEN_VERYLOW + LED_BLUE_VERYLOW)
#define LED_CYAN_LOW       (LED_GREEN_LOW     + LED_BLUE_LOW)
#define LED_CYAN_MEDIUM    (LED_GREEN_MEDIUM  + LED_BLUE_MEDIUM)
#define LED_CYAN_HIGH      (LED_GREEN_HIGH    + LED_BLUE_HIGH)

#define LED_WHITE_VERYLOW  (LED_RED_VERYLOW + LED_GREEN_VERYLOW + LED_BLUE_VERYLOW)
#define LED_WHITE_LOW      (LED_RED_LOW     + LED_GREEN_LOW     + LED_BLUE_LOW)
#define LED_WHITE_MEDIUM   (LED_RED_MEDIUM  + LED_GREEN_MEDIUM  + LED_BLUE_MEDIUM)
#define LED_WHITE_HIGH     (LED_RED_HIGH    + LED_GREEN_HIGH    + LED_BLUE_HIGH)

static const uint8_t PROGMEM
    mono_bmp[][8] =
    {
        {   B10101010, // 0: checkered 1
            B01010101,
            B10101010,
            B01010101,
            B10101010,
            B01010101,
            B10101010,
            B01010101 },
        {   B01010101, // 1: checkered 2
            B10101010,
            B01010101,
            B10101010,
            B01010101,
            B10101010,
            B01010101,
            B10101010 },
        {   B00111100, // 2: smiley
            B01000010,
            B10100101,
            B10000001,
            B10100101,
            B10011001,
            B01000010,
            B00111100 },
        {   B00111100, // 3: neutral
            B01000010,
            B10100101,
            B10000001,
            B10111101,
            B10000001,
            B01000010,
            B00111100 },
        {   B00111100, // 4; frowny
            B01000010,
            B10100101,
            B10000001,
            B10011001,
            B10100101,
            B01000010,
            B00111100 },
    };

static const uint16_t PROGMEM
    // These bitmaps were written for a backend that only supported
    // 4 bits per color with Blue/Green/Red ordering while neomatrix
    // uses native 565 color mapping as RGB.
    // I'm leaving the arrays as is because it's easier to read
    // which color is what when separated on a 4bit boundary
    // The demo code will modify the arrays at runtime to be compatible
    // with the neomatrix color ordering and bit depth.
    RGB_bmp[][64] = {
      // 00: blue, blue/red, red, red/green, green, green/blue, blue, white
      { 0x100, 0x200, 0x300, 0x400, 0x600, 0x800, 0xA00, 0xF00,
        0x101, 0x202, 0x303, 0x404, 0x606, 0x808, 0xA0A, 0xF0F,
        0x001, 0x002, 0x003, 0x004, 0x006, 0x008, 0x00A, 0x00F,
        0x011, 0x022, 0x033, 0x044, 0x066, 0x088, 0x0AA, 0x0FF,
        0x010, 0x020, 0x030, 0x040, 0x060, 0x080, 0x0A0, 0x0F0,
        0x110, 0x220, 0x330, 0x440, 0x660, 0x880, 0xAA0, 0xFF0,
        0x100, 0x200, 0x300, 0x400, 0x600, 0x800, 0xA00, 0xF00,
        0x111, 0x222, 0x333, 0x444, 0x666, 0x888, 0xAAA, 0xFFF, },

      // 01: grey to white
      { 0x111, 0x222, 0x333, 0x555, 0x777, 0x999, 0xAAA, 0xFFF,
        0x222, 0x222, 0x333, 0x555, 0x777, 0x999, 0xAAA, 0xFFF,
        0x333, 0x333, 0x333, 0x555, 0x777, 0x999, 0xAAA, 0xFFF,
        0x555, 0x555, 0x555, 0x555, 0x777, 0x999, 0xAAA, 0xFFF,
        0x777, 0x777, 0x777, 0x777, 0x777, 0x999, 0xAAA, 0xFFF,
        0x999, 0x999, 0x999, 0x999, 0x999, 0x999, 0xAAA, 0xFFF,
        0xAAA, 0xAAA, 0xAAA, 0xAAA, 0xAAA, 0xAAA, 0xAAA, 0xFFF,
        0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, },

      // 02: low red to high red
      { 0x001, 0x002, 0x003, 0x005, 0x007, 0x009, 0x00A, 0x00F,
        0x002, 0x002, 0x003, 0x005, 0x007, 0x009, 0x00A, 0x00F,
        0x003, 0x003, 0x003, 0x005, 0x007, 0x009, 0x00A, 0x00F,
        0x005, 0x005, 0x005, 0x005, 0x007, 0x009, 0x00A, 0x00F,
        0x007, 0x007, 0x007, 0x007, 0x007, 0x009, 0x00A, 0x00F,
        0x009, 0x009, 0x009, 0x009, 0x009, 0x009, 0x00A, 0x00F,
        0x00A, 0x00A, 0x00A, 0x00A, 0x00A, 0x00A, 0x00A, 0x00F,
        0x00F, 0x00F, 0x00F, 0x00F, 0x00F, 0x00F, 0x00F, 0x00F, },

      // 03: low green to high green
      { 0x010, 0x020, 0x030, 0x050, 0x070, 0x090, 0x0A0, 0x0F0,
        0x020, 0x020, 0x030, 0x050, 0x070, 0x090, 0x0A0, 0x0F0,
        0x030, 0x030, 0x030, 0x050, 0x070, 0x090, 0x0A0, 0x0F0,
        0x050, 0x050, 0x050, 0x050, 0x070, 0x090, 0x0A0, 0x0F0,
        0x070, 0x070, 0x070, 0x070, 0x070, 0x090, 0x0A0, 0x0F0,
        0x090, 0x090, 0x090, 0x090, 0x090, 0x090, 0x0A0, 0x0F0,
        0x0A0, 0x0A0, 0x0A0, 0x0A0, 0x0A0, 0x0A0, 0x0A0, 0x0F0,
        0x0F0, 0x0F0, 0x0F0, 0x0F0, 0x0F0, 0x0F0, 0x0F0, 0x0F0, },

      // 04: low blue to high blue
      { 0x100, 0x200, 0x300, 0x500, 0x700, 0x900, 0xA00, 0xF00,
        0x200, 0x200, 0x300, 0x500, 0x700, 0x900, 0xA00, 0xF00,
        0x300, 0x300, 0x300, 0x500, 0x700, 0x900, 0xA00, 0xF00,
        0x500, 0x500, 0x500, 0x500, 0x700, 0x900, 0xA00, 0xF00,
        0x700, 0x700, 0x700, 0x700, 0x700, 0x900, 0xA00, 0xF00,
        0x900, 0x900, 0x900, 0x900, 0x900, 0x900, 0xA00, 0xF00,
        0xA00, 0xA00, 0xA00, 0xA00, 0xA00, 0xA00, 0xA00, 0xF00,
        0xF00, 0xF00, 0xF00, 0xF00, 0xF00, 0xF00, 0xF00, 0xF00, },

      // 05: 1 black, 2R, 2O, 2G, 1B with 4 blue lines rising right
      { 0x000, 0x200, 0x000, 0x400, 0x000, 0x800, 0x000, 0xF00,
        0x000, 0x201, 0x002, 0x403, 0x004, 0x805, 0x006, 0xF07,
        0x008, 0x209, 0x00A, 0x40B, 0x00C, 0x80D, 0x00E, 0xF0F,
        0x000, 0x211, 0x022, 0x433, 0x044, 0x855, 0x066, 0xF77,
        0x088, 0x299, 0x0AA, 0x4BB, 0x0CC, 0x8DD, 0x0EE, 0xFFF,
        0x000, 0x210, 0x020, 0x430, 0x040, 0x850, 0x060, 0xF70,
        0x080, 0x290, 0x0A0, 0x4B0, 0x0C0, 0x8D0, 0x0E0, 0xFF0,
        0x000, 0x200, 0x000, 0x500, 0x000, 0x800, 0x000, 0xF00, },

      // 06: 4 lines of increasing red and then green
      { 0x000, 0x000, 0x001, 0x001, 0x002, 0x002, 0x003, 0x003,
        0x004, 0x004, 0x005, 0x005, 0x006, 0x006, 0x007, 0x007,
        0x008, 0x008, 0x009, 0x009, 0x00A, 0x00A, 0x00B, 0x00B,
        0x00C, 0x00C, 0x00D, 0x00D, 0x00E, 0x00E, 0x00F, 0x00F,
        0x000, 0x000, 0x010, 0x010, 0x020, 0x020, 0x030, 0x030,
        0x040, 0x040, 0x050, 0x050, 0x060, 0x060, 0x070, 0x070,
        0x080, 0x080, 0x090, 0x090, 0x0A0, 0x0A0, 0x0B0, 0x0B0,
        0x0C0, 0x0C0, 0x0D0, 0x0D0, 0x0E0, 0x0E0, 0x0F0, 0x0F0, },

      // 07: 4 lines of increasing red and then blue
      { 0x000, 0x000, 0x001, 0x001, 0x002, 0x002, 0x003, 0x003,
        0x004, 0x004, 0x005, 0x005, 0x006, 0x006, 0x007, 0x007,
        0x008, 0x008, 0x009, 0x009, 0x00A, 0x00A, 0x00B, 0x00B,
        0x00C, 0x00C, 0x00D, 0x00D, 0x00E, 0x00E, 0x00F, 0x00F,
        0x000, 0x000, 0x100, 0x100, 0x200, 0x200, 0x300, 0x300,
        0x400, 0x400, 0x500, 0x500, 0x600, 0x600, 0x700, 0x700,
        0x800, 0x800, 0x900, 0x900, 0xA00, 0xA00, 0xB00, 0xB00,
        0xC00, 0xC00, 0xD00, 0xD00, 0xE00, 0xE00, 0xF00, 0xF00, },

      // 08: criss cross of green and red with diagonal blue.
      { 0xF00, 0x001, 0x003, 0x005, 0x007, 0x00A, 0x00F, 0x000,
        0x020, 0xF21, 0x023, 0x025, 0x027, 0x02A, 0x02F, 0x020,
        0x040, 0x041, 0xF43, 0x045, 0x047, 0x04A, 0x04F, 0x040,
        0x060, 0x061, 0x063, 0xF65, 0x067, 0x06A, 0x06F, 0x060,
        0x080, 0x081, 0x083, 0x085, 0xF87, 0x08A, 0x08F, 0x080,
        0x0A0, 0x0A1, 0x0A3, 0x0A5, 0x0A7, 0xFAA, 0x0AF, 0x0A0,
        0x0F0, 0x0F1, 0x0F3, 0x0F5, 0x0F7, 0x0FA, 0xFFF, 0x0F0,
        0x000, 0x001, 0x003, 0x005, 0x007, 0x00A, 0x00F, 0xF00, },

      // 09: 2 lines of green, 2 red, 2 orange, 2 green
      { 0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0,
        0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0,
        0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0,
        0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0,
        0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0,
        0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0,
        0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0,
        0x0F0, 0x0F0, 0x0FF, 0x0FF, 0x00F, 0x00F, 0x0F0, 0x0F0, },

      // 10: multicolor smiley face
      { 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);

        //Serial.print(color, HEX);
        b = (color & 0xF00) >> 8;
        g = (color & 0x0F0) >> 4;
        r = color & 0x00F;
        //Serial.print(" ");
        //Serial.print(b);
        //Serial.print("/");
        //Serial.print(g);
        //Serial.print("/");
        //Serial.print(r);
        //Serial.print(" -> ");
        // 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);
        //Serial.print(r);
        //Serial.print("/");
        //Serial.print(g);
        //Serial.print("/");
        //Serial.print(b);
        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);
}

// Fill the screen with multiple levels of white to gauge the quality


void display_bitmap(uint8_t bmp_num, uint16_t color) {
    static uint16_t bmx,bmy;

    // Clear the space under the bitmap that will be drawn as
    // drawing a single color pixmap does not write over pixels
    // that are nul, and leaves the data that was underneath
    matrix->fillRect(bmx,bmy, bmx+8,bmy+8, LED_BLACK);
    matrix->drawBitmap(bmx, bmy, mono_bmp[bmp_num], 8, 8, color);
    bmx += 8;
    if (bmx >= mw) bmx = 0;
    if (!bmx) bmy += 8;
    if (bmy >= mh) bmy = 0;
    matrix->show();
}

void display_rgbBitmap(uint8_t bmp_num) {
    static uint16_t bmx,bmy;

    fixdrawRGBBitmap(bmx, bmy, RGB_bmp[bmp_num], 8, 8);
    bmx += 8;
    if (bmx >= mw) bmx = 0;
    if (!bmx) bmy += 8;
    if (bmy >= mh) bmy = 0;
    matrix->show();
}







void loop() {
    // clear the screen after X bitmaps have been displayed and we
    // loop back to the top left corner
    // 8x8 => 1, 16x8 => 2, 17x9 => 6
    static uint8_t pixmap_count = ((mw+7)/8) * ((mh+7)/8);

    Serial.print("Screen pixmap capacity: ");
    Serial.println(pixmap_count);

    // multicolor bitmap sent as many times as we can display an 8x8 pixmap
    for (uint8_t i=0; i<=pixmap_count; i++) {
        display_rgbBitmap(0);
    }
    delay(1000);

   

    // Cycle through red, green, blue, display 2 checkered patterns
    // useful to debug some screen types and alignment.
    uint16_t bmpcolor[] = { LED_GREEN_HIGH, LED_BLUE_HIGH, LED_RED_HIGH };
    for (uint8_t i=0; i<3; i++) {
//        display_bitmap(0, bmpcolor[i]);
        delay(500);
//        display_bitmap(1, bmpcolor[i]);
        delay(500);
    }

   

    for (uint8_t i=0; i<=(sizeof(RGB_bmp)/sizeof(RGB_bmp[0])-1); i++) {
        display_rgbBitmap(i);
        delay(mw>8?500:1500);
    }
    // If we have multiple pixmaps displayed at once, wait a bit longer on the last.
    delay(mw>8?1000:500);

  
}

void setup() {
    Serial.begin(115200);
    matrix->begin();
    matrix->setTextWrap(false);
    matrix->setBrightness(BRIGHTNESS);
    // Test full bright of all LEDs. If brightness is too high
    // for your current limit (i.e. USB), decrease it.
    //matrix->fillScreen(LED_WHITE_HIGH);
    matrix->show();
    delay(1000);
    matrix->clear();
}

// vim:sts=4:sw=4

 

 

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

댓글