Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Written By Kouzerumatsukite; 25 JUNE 2023
- #include <Arduino.h>
- #include <SPI.h>
- // Assign these ESP32 pins to P10 Board
- #define DR 23 // -> DR // Data-Receive
- #define OE 21 // -> OE // Output-Enable
- #define CLK 18 // -> CLK // Data-Clock
- #define LAT 5 // -> LAT // Data-Latch
- #define RSA 32 // -> A // Row Select A
- #define RSB 33 // -> B // Row Select B
- // the way of how the data is arranged in the display is stupid
- // but we're gonna follow it anyway, its arranged like this:
- // row 0-3: 0 4 8 C // Each hex notation stores byte (8 pixels)
- // row 4-7: 1 5 9 D // DR IN -> 0123456789ABCDEF -> DR OUT
- // row 8-B: 2 6 A E // board -> MATRIX ROW DATA -> next matrix
- // row C-F: 3 7 B F // the four rows selected by RSA / RSB pins
- uint8_t display_data[4][16];
- int current_row=0;
- void displayRow(){
- // turn off display
- digitalWrite(OE,LOW);
- // update row select
- int row = current_row++ & 3;
- digitalWrite(RSA,row>>0&1);
- digitalWrite(RSB,row>>1&1);
- // update row data
- SPI.writeBytes((uint8_t*)display_data[row], 16);
- digitalWrite(LAT,HIGH);
- digitalWrite(LAT,LOW);
- // turn on display
- digitalWrite(OE,HIGH);
- return;
- }
- const uint8_t bitmap_test_00[] = { 0xC0, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x03, };
- const uint8_t bitmap_test_01[] = { 0x00, 0x00, 0x00, 0x00, 0x01, 0x44, 0xA4, 0x00, 0xA3, 0x0C, 0x34, 0x00, 0xA5, 0x54, 0xA4, 0x00, 0xA5, 0x54, 0xA0, 0x00, 0x63, 0x4C, 0x94, 0x81, 0x00, 0x00, 0x01, 0x83, 0x00, 0x00, 0x03, 0xC7, 0x4A, 0x6E, 0x83, 0xFF, 0x6A, 0x88, 0x86, 0xF7, 0x5A, 0x8C, 0x85, 0x6B, 0x4A, 0x88, 0x05, 0x6B, 0x4A, 0x6E, 0x87, 0xFF, 0x00, 0x00, 0x0F, 0x77, 0x00, 0x00, 0x03, 0xCE, 0x00, 0x00, 0x00, 0xF8, };
- const uint8_t bitmap_test_02[] = { 0xFE, 0x00, 0x7F, 0xC0, 0x82, 0x00, 0x40, 0x40, 0x82, 0x00, 0x40, 0x40, 0x82, 0x00, 0x40, 0x40, 0x82, 0x00, 0x40, 0x40, 0x82, 0x00, 0x40, 0x40, 0x82, 0x00, 0x40, 0x40, 0xE2, 0x00, 0x70, 0x40, 0xE2, 0x00, 0x70, 0x40, 0xE2, 0x00, 0x70, 0x40, 0xE2, 0x00, 0x70, 0x40, 0xE2, 0x00, 0x70, 0x40, 0xE2, 0x22, 0x70, 0x40, 0xE2, 0x22, 0x70, 0x40, 0xE2, 0x2A, 0x70, 0x40, 0xFE, 0x3E, 0x7F, 0xC0, };
- const uint8_t bitmap_test_03[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, };
- // function to load bitmap into display, in correct order
- void loadBitmap(const uint8_t* bitmap_data){
- for(int y=0; y<4; y++){
- for(int x=0; x<16; x++){
- int i = (x/4)+4*(y+4*(3-(x%4)));
- display_data[y][x] = ~bitmap_data[i];
- }
- }
- }
- void setup() {
- // initialize pin states
- pinMode(DR ,OUTPUT);
- pinMode(OE ,OUTPUT);
- pinMode(CLK,OUTPUT);
- pinMode(LAT,OUTPUT);
- pinMode(RSA,OUTPUT);
- pinMode(RSB,OUTPUT);
- // initialize SPI
- SPI.begin(CLK, -1, DR, -1);
- SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0));
- }
- void displayDelay(int millisec){
- int finish_time = millis() + millisec;
- while (finish_time - millis() > 0){
- displayRow();
- delay(1);
- }
- }
- void loop() {
- // load bitmaps and display
- loadBitmap(bitmap_test_00);
- displayDelay(2500);
- loadBitmap(bitmap_test_01);
- displayDelay(2500);
- loadBitmap(bitmap_test_02);
- displayDelay(2500);
- loadBitmap(bitmap_test_03);
- displayDelay(2500);
- }
Advertisement
Add Comment
Please, Sign In to add comment