A-KouZ1

P10_simple

Jun 25th, 2023
831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.81 KB | Source Code | 0 0
  1. // Written By Kouzerumatsukite; 25 JUNE 2023
  2. #include <Arduino.h>
  3. #include <SPI.h>
  4.  
  5. // Assign these ESP32 pins to P10 Board
  6. #define DR  23 // -> DR   // Data-Receive
  7. #define OE  21 // -> OE   // Output-Enable
  8. #define CLK 18 // -> CLK  // Data-Clock
  9. #define LAT  5 // -> LAT  // Data-Latch
  10. #define RSA 32 // -> A    // Row Select A
  11. #define RSB 33 // -> B    // Row Select B
  12.  
  13. // the way of how the data is arranged in the display is stupid
  14. // but we're gonna follow it anyway, its arranged like this:
  15. // row 0-3: 0 4 8 C // Each hex notation stores byte (8 pixels)
  16. // row 4-7: 1 5 9 D // DR IN -> 0123456789ABCDEF -> DR OUT
  17. // row 8-B: 2 6 A E // board -> MATRIX ROW DATA  -> next matrix
  18. // row C-F: 3 7 B F // the four rows selected by RSA / RSB pins
  19.  
  20. uint8_t display_data[4][16];
  21. int current_row=0;
  22.  
  23. void displayRow(){
  24.   // turn off display
  25.   digitalWrite(OE,LOW);
  26.   // update row select
  27.   int row = current_row++ & 3;
  28.   digitalWrite(RSA,row>>0&1);
  29.   digitalWrite(RSB,row>>1&1);
  30.   // update row data
  31.   SPI.writeBytes((uint8_t*)display_data[row], 16);
  32.   digitalWrite(LAT,HIGH);
  33.   digitalWrite(LAT,LOW);
  34.   // turn on display
  35.   digitalWrite(OE,HIGH);
  36.   return;
  37. }
  38.  
  39. 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,  };
  40. 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,  };
  41. 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,  };
  42. 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,  };
  43. // function to load bitmap into display, in correct order
  44. void loadBitmap(const uint8_t* bitmap_data){
  45.   for(int y=0; y<4; y++){
  46.     for(int x=0; x<16; x++){
  47.       int i = (x/4)+4*(y+4*(3-(x%4)));
  48.       display_data[y][x] = ~bitmap_data[i];
  49.     }
  50.   }
  51. }
  52.  
  53. void setup() {
  54.   // initialize pin states
  55.   pinMode(DR ,OUTPUT);
  56.   pinMode(OE ,OUTPUT);
  57.   pinMode(CLK,OUTPUT);
  58.   pinMode(LAT,OUTPUT);
  59.   pinMode(RSA,OUTPUT);
  60.   pinMode(RSB,OUTPUT);
  61.   // initialize SPI
  62.   SPI.begin(CLK, -1, DR, -1);
  63.   SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0));
  64. }
  65.  
  66. void displayDelay(int millisec){
  67.   int finish_time = millis() + millisec;
  68.   while (finish_time - millis() > 0){
  69.     displayRow();
  70.     delay(1);
  71.   }
  72. }
  73.  
  74. void loop() {
  75.   // load bitmaps and display
  76.   loadBitmap(bitmap_test_00);
  77.   displayDelay(2500);
  78.   loadBitmap(bitmap_test_01);
  79.   displayDelay(2500);
  80.   loadBitmap(bitmap_test_02);
  81.   displayDelay(2500);
  82.   loadBitmap(bitmap_test_03);
  83.   displayDelay(2500);
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment