Advertisement
pleasedontcode

"LED Display" rev_01

Jun 11th, 2024
408
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "LED Display"
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-06-11 22:48:13
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Generate an 8x8 LED matrix using WS2801 LEDs */
  21.     /* controlled by FastLED library. Display the string */
  22.     /* "pleasedontcode" on the matrix, showing each */
  23.     /* character every 0.5 seconds using digital pins D4 */
  24.     /* and D13 for data and clock. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <FastLED.h>  //https://github.com/FastLED/FastLED
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs(void);
  34. void displayCharacter(char c);
  35.  
  36. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  37. const uint8_t strip_WS2801_DIN_PIN_D4 = 4;
  38. const uint8_t strip_WS2801_CIN_PIN_D13 = 13;
  39.  
  40. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  41. /***** used to store raw data *****/
  42. bool strip_WS2801_DIN_PIN_D4_rawData = 0;
  43. bool strip_WS2801_CIN_PIN_D13_rawData = 0;
  44.  
  45. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  46. /***** used to store data after characteristic curve transformation *****/
  47. float strip_WS2801_DIN_PIN_D4_phyData = 0.0;
  48. float strip_WS2801_CIN_PIN_D13_phyData = 0.0;
  49.  
  50. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  51. #define NUM_LEDS 64
  52. #define DATA_PIN 4
  53. #define CLOCK_PIN 13
  54. #define BRIGHTNESS 64
  55.  
  56. CRGB leds[NUM_LEDS];
  57.  
  58. const uint8_t kMatrixWidth = 8;
  59. const uint8_t kMatrixHeight = 8;
  60. const bool kMatrixSerpentineLayout = true;
  61.  
  62. /****** CHARACTER BITMAPS *****/
  63. // Define bitmaps for characters 'a' to 'z' and space
  64. const uint8_t charBitmaps[27][8] = {
  65.     // 'a'
  66.     {0b00000000, 0b01100000, 0b10010000, 0b10000000, 0b11110000, 0b10010000, 0b10010000, 0b01100000},
  67.     // 'b'
  68.     {0b00000000, 0b11100000, 0b10010000, 0b10010000, 0b11100000, 0b10010000, 0b10010000, 0b11100000},
  69.     // 'c'
  70.     {0b00000000, 0b01100000, 0b10010000, 0b10000000, 0b10000000, 0b10000000, 0b10010000, 0b01100000},
  71.     // 'd'
  72.     {0b00000000, 0b11100000, 0b10010000, 0b10010000, 0b10010000, 0b10010000, 0b10010000, 0b11100000},
  73.     // 'e'
  74.     {0b00000000, 0b11110000, 0b10000000, 0b10000000, 0b11100000, 0b10000000, 0b10000000, 0b11110000},
  75.     // 'f'
  76.     {0b00000000, 0b11110000, 0b10000000, 0b10000000, 0b11100000, 0b10000000, 0b10000000, 0b10000000},
  77.     // 'g'
  78.     {0b00000000, 0b01100000, 0b10010000, 0b10000000, 0b10110000, 0b10010000, 0b10010000, 0b01100000},
  79.     // 'h'
  80.     {0b00000000, 0b10010000, 0b10010000, 0b10010000, 0b11110000, 0b10010000, 0b10010000, 0b10010000},
  81.     // 'i'
  82.     {0b00000000, 0b11100000, 0b01000000, 0b01000000, 0b01000000, 0b01000000, 0b01000000, 0b11100000},
  83.     // 'j'
  84.     {0b00000000, 0b11110000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b10010000, 0b01100000},
  85.     // 'k'
  86.     {0b00000000, 0b10010000, 0b10100000, 0b11000000, 0b11000000, 0b10100000, 0b10010000, 0b10010000},
  87.     // 'l'
  88.     {0b00000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b11110000},
  89.     // 'm'
  90.     {0b00000000, 0b10010000, 0b11110000, 0b11110000, 0b10101000, 0b10101000, 0b10101000, 0b10101000},
  91.     // 'n'
  92.     {0b00000000, 0b10010000, 0b11010000, 0b11010000, 0b10110000, 0b10110000, 0b10010000, 0b10010000},
  93.     // 'o'
  94.     {0b00000000, 0b01100000, 0b10010000, 0b10010000, 0b10010000, 0b10010000, 0b10010000, 0b01100000},
  95.     // 'p'
  96.     {0b00000000, 0b11100000, 0b10010000, 0b10010000, 0b11100000, 0b10000000, 0b10000000, 0b10000000},
  97.     // 'q'
  98.     {0b00000000, 0b01100000, 0b10010000, 0b10010000, 0b10010000, 0b10110000, 0b01100000, 0b00010000},
  99.     // 'r'
  100.     {0b00000000, 0b11100000, 0b10010000, 0b10010000, 0b11100000, 0b10100000, 0b10010000, 0b10010000},
  101.     // 's'
  102.     {0b00000000, 0b01100000, 0b10010000, 0b10000000, 0b01100000, 0b00010000, 0b10010000, 0b01100000},
  103.     // 't'
  104.     {0b00000000, 0b11100000, 0b01000000, 0b01000000, 0b01000000, 0b01000000, 0b01000000, 0b01000000},
  105.     // 'u'
  106.     {0b00000000, 0b10010000, 0b10010000, 0b10010000, 0b10010000, 0b10010000, 0b10010000, 0b01100000},
  107.     // 'v'
  108.     {0b00000000, 0b10010000, 0b10010000, 0b10010000, 0b10010000, 0b10010000, 0b01100000, 0b01100000},
  109.     // 'w'
  110.     {0b00000000, 0b10101000, 0b10101000, 0b10101000, 0b10101000, 0b10101000, 0b11110000, 0b10010000},
  111.     // 'x'
  112.     {0b00000000, 0b10010000, 0b10010000, 0b01100000, 0b01100000, 0b01100000, 0b10010000, 0b10010000},
  113.     // 'y'
  114.     {0b00000000, 0b10010000, 0b10010000, 0b10010000, 0b01110000, 0b00010000, 0b10010000, 0b01100000},
  115.     // 'z'
  116.     {0b00000000, 0b11110000, 0b00010000, 0b00100000, 0b01000000, 0b10000000, 0b10000000, 0b11110000},
  117.     // ' '
  118.     {0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000}
  119. };
  120.  
  121. /****** FUNCTION DEFINITIONS *****/
  122. void setup(void)
  123. {
  124.     // put your setup code here, to run once:
  125.     pinMode(strip_WS2801_DIN_PIN_D4, OUTPUT);
  126.     pinMode(strip_WS2801_CIN_PIN_D13, OUTPUT);
  127.  
  128.     // Initialize the FastLED library
  129.     FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  130.     FastLED.setBrightness(BRIGHTNESS);
  131. }
  132.  
  133. void loop(void)
  134. {
  135.     // put your main code here, to run repeatedly:
  136.     updateOutputs(); // Refresh output data
  137.  
  138.     // Display the string "pleasedontcode"
  139.     const char* message = "pleasedontcode";
  140.     for (int i = 0; message[i] != '\0'; i++) {
  141.         displayCharacter(message[i]);
  142.         FastLED.show();
  143.         delay(500);
  144.     }
  145. }
  146.  
  147. void updateOutputs()
  148. {
  149.     digitalWrite(strip_WS2801_DIN_PIN_D4, strip_WS2801_DIN_PIN_D4_rawData);
  150.     digitalWrite(strip_WS2801_CIN_PIN_D13, strip_WS2801_CIN_PIN_D13_rawData);
  151. }
  152.  
  153. uint16_t XY(uint8_t x, uint8_t y) {
  154.     uint16_t i;
  155.     if (kMatrixSerpentineLayout) {
  156.         i = (y & 0x01) ? (y * kMatrixWidth) + (kMatrixWidth - 1 - x) : (y * kMatrixWidth) + x;
  157.     } else {
  158.         i = (y * kMatrixWidth) + x;
  159.     }
  160.     return i;
  161. }
  162.  
  163. void displayCharacter(char c) {
  164.     int index = (c == ' ') ? 26 : (c - 'a');
  165.     for (uint8_t y = 0; y < kMatrixHeight; y++) {
  166.         for (uint8_t x = 0; x < kMatrixWidth; x++) {
  167.             if (charBitmaps[index][y] & (1 << (7 - x))) {
  168.                 leds[XY(x, y)] = CRGB::White;
  169.             } else {
  170.                 leds[XY(x, y)] = CRGB::Black;
  171.             }
  172.         }
  173.     }
  174. }
  175.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement