Guest User

Untitled

a guest
Apr 19th, 2021
9
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_GFX.h>
  2. #include <Adafruit_TFTLCD.h>
  3. #include <SD.h>
  4. #include <SPI.h>
  5. #define LCD_CS A3
  6. #define LCD_CD A2
  7. #define LCD_WR A1
  8. #define LCD_RD A0
  9. #define SD_CS 10
  10. Adafruit_TFTLCD display(LCD_CS, LCD_CD, LCD_WR, LCD_RD, A4);
  11.  
  12. #define BLACK 0x0000
  13. #define BLUE 0x001F
  14. #define RED 0xF800
  15. #define GREEN 0x07E0
  16. #define CYAN 0x07FF
  17. #define MAGENTA 0xF81F
  18. #define YELLOW 0xFFE0
  19. #define WHITE 0xFFFF
  20. #define ORANGE 0xFD20
  21. #define GREENYELLOW 0xAFE5
  22. #define NAVY 0x000F
  23. #define DARKGREEN 0x03E0
  24. #define DARKCYAN 0x03EF
  25. #define MAROON 0x7800
  26. #define PURPLE 0x780F
  27. #define OLIVE 0x7BE0
  28. #define LIGHTGREY 0xC618
  29. #define DARKGREY 0x7BEF
  30. uint8_t previous_mode = 0;
  31. void setup() {
  32.   Serial.begin(9600);
  33.   Serial.println(F("TFT LCD test"));
  34. #ifdef USE_ADAFRUIT_SHIELD_PINOUT
  35.   Serial.println(F("Using Adafruit 2.4\" TFT Arduino Shield Pinout"));
  36. #else
  37.   Serial.println(F("Using Adafruit 2.4\" TFT Breakout Board Pinout"));
  38. #endif
  39.   Serial.print("TFT size is ");
  40.   Serial.print(display.width());
  41.   Serial.print("x");
  42.   Serial.println(display.height());
  43.   display.reset();
  44.   uint16_t identifier = display.readID();
  45.   if (identifier == 0x9325) {
  46.     Serial.println(F("Found ILI9325 LCD driver"));
  47.   } else if (identifier == 0x9328) {
  48.     Serial.println(F("Found ILI9328 LCD driver"));
  49.   } else if (identifier == 0x7575) {
  50.     Serial.println(F("Found HX8347G LCD driver"));
  51.   } else if (identifier == 0x9341) {
  52.     Serial.println(F("Found ILI9341 LCD driver"));
  53.   } else if (identifier == 0x8357) {
  54.     Serial.println(F("Found HX8357D LCD driver"));
  55.   } else {
  56.     Serial.print(F("Unknown LCD driver chip: "));
  57.     Serial.println(identifier, HEX);
  58.     return;
  59.   }
  60.   display.begin(identifier);
  61.   display.setRotation(3);
  62.  
  63.   Serial.print(F("Initializing SD card..."));
  64.   if (!SD.begin(SD_CS)) {
  65.     Serial.println(F("failed!"));
  66.     return;
  67.   }
  68. }
  69. void loop() {
  70.   uint8_t current_mode = random(0, 6);
  71.   current_mode = 3;
  72.  
  73.   if (current_mode != previous_mode) {
  74.     display.fillScreen(BLACK);
  75.     switch (current_mode) {
  76.       case 0: {
  77.           drawTarget(WHITE);
  78.           drawCompositeWave(0, 0, display.width(), display.height(), 2, 2, 0.5, 3, 0.1, 6, random(1, 360), GREENYELLOW);
  79.           break;
  80.         }
  81.       case 1: {
  82.           drawGrid(24, WHITE);
  83.           drawCompositeWave(0, 0, display.width(), display.height(), 2, 3, 0.33, 4, 0.25, 5, random(1, 360), GREENYELLOW);
  84.           break;
  85.         }
  86.       case 2: {
  87.           drawCircularGauge(display.width() / 2 - (display.height() - 40) / 2, 20, display.height() - 40, display.height() - 40, 16, 180, 75, WHITE);
  88.           drawCompositeWave(display.width() / 2 - 60, display.height() / 2 - 60, 120, 120, 4, 2, 0.75, 3, 0.1, 6, random(1, 360), GREENYELLOW);
  89.           drawHorizontalRandomBarChart(8, 8, 40, display.height() * 0.75, 8, 4, RED);
  90.           drawVerticalTriangleGauge(display.width() - 40, 40, 32, 60, WHITE, RED, 60);
  91.           break;
  92.         }
  93.       case 3: {
  94.           bmpDraw("samhain.bmp", 0, 0);
  95.           drawHorizontalRandomBarChart(8, 16, 40, display.height() * 0.4, 8, 4, RED);
  96.           display.setCursor(display.width() - 24, 0);
  97.           display.setTextColor(RED);
  98.           display.setTextSize(4);
  99.           display.print("6");
  100.           delay(500);
  101.           break;
  102.         }
  103.       case 4: {
  104.           display.fillRect(0, display.height() * 0.625, display.width(), display.height() * 0.375, DARKGREEN);
  105.           drawBorder(WHITE);
  106.           drawCompositeWave(0, 0, display.width(), display.height() * 0.6, 2, 3, 0.33, 4, 0.25, 5, random(1, 360), WHITE);
  107.           drawCompositeWave(0, display.height() * 0.625, display.width(), display.height() * 0.375, 4, 2, 0.75, 3, 0.1, 6, random(1, 360), RED);
  108.           break;
  109.         }
  110.       case 5: {
  111.           drawGrid(display.width() / 6 + 0.5, WHITE);
  112.           display.drawCircle(display.width() / 2, display.height(), display.height() * 0.9, WHITE);
  113.           display.drawCircle(display.width() / 2, display.height(), display.height() * 0.6, WHITE);
  114.           display.drawCircle(display.width() / 2, display.height(), display.height() * 0.3, WHITE);
  115.           display.fillCircle(display.width() * 0.75, display.height() * 0.25, 8, GREEN);
  116.           display.fillCircle(display.width() * 0.75, display.height() * 0.25, 6, GREENYELLOW);
  117.           break;
  118.         }
  119.       case 6: {
  120.           drawTarget(WHITE);
  121.           drawSineWave(0, 0, display.width(), display.height(), 0.66, 3, random(1, 360), GREEN);
  122.           break;
  123.         }
  124.       case 7: {
  125.           display.drawLine(display.width() / 2, 20, display.width() / 2, display.height() - 19, WHITE);
  126.           display.drawLine(display.width() / 2 + 20, display.height() / 2, display.width() - 20, display.height() / 2, WHITE);
  127.           display.setCursor(display.width() - 64, 20);
  128.           display.setTextColor(RED);
  129.           display.setTextSize(8);
  130.           display.print("6");
  131.           delay(500);
  132.           drawHorizontalRandomBarChart(20, 20, display.width() * 0.33, display.height() / 3, 8, 4, RED);
  133.           drawVerticalRandomBarChart(20, display.height() / 2, display.width() * 0.33, display.height() * 0.4, 8, 4, GREEN);
  134.           drawSineWave(display.width() / 2 + 20, display.height() / 2, display.width() * 0.4, display.height() / 2 - 20, 0.4, 7, random(1, 360), GREEN);
  135.           break;
  136.         }
  137.         delay(1000);
  138.     }
  139.   }
  140.   previous_mode = current_mode;
  141. }
  142.  
  143. void drawBorder(uint16_t color) {
  144.   display.drawRect(0, 0, display.width(), display.height(), color);
  145. }
  146.  
  147. void drawGrid(uint8_t step_size, uint16_t color) {
  148.   drawBorder(color);
  149.   for (uint16_t x = 0; x <= display.width(); x += step_size) {
  150.     display.drawLine(x, 0, x, display.height(), color);
  151.   }
  152.   for (uint16_t y = 0; y <= display.height(); y += step_size) {
  153.     display.drawLine(0, y, display.width(), y, color);
  154.   }
  155. }
  156.  
  157. void drawTarget(uint16_t color) {
  158.   uint8_t border = 8, step_size = 16, line_width = 10, line_step = line_width / 2;
  159.   uint16_t x_start = border - 1, x_center = display.width() / 2, x_end = display.width() - border, y_start = border - 1, y_center = display.height() / 2, y_end = display.height() - border;
  160.   display.drawLine(x_center, y_start, x_center, y_end, color);
  161.   display.drawLine(x_start, y_center, x_end, y_center, color);
  162.  
  163.   //Vertical steps
  164.   display.drawLine(x_start, y_center - line_step * 4, x_start, y_center + line_step * 4, color);
  165.   display.drawLine(x_start + step_size, y_center - line_step * 2, x_start + step_size, y_center + line_step * 2, color);
  166.   display.drawLine(x_end - step_size, y_center - line_step * 2, x_end - step_size, y_center + line_step * 2, color);
  167.   display.drawLine(x_end, y_center - line_step * 4, x_end, y_center + line_step * 4, color);
  168.   for (uint16_t x_current = x_start + 2 * step_size; x_current < x_end - 2 * step_size; x_current += step_size) {
  169.     display.drawLine(x_current, y_center - line_step, x_current, y_center + line_step, color);
  170.   }
  171.  
  172.   //Horizontal steps
  173.   display.drawLine(x_center - line_step * 4, y_start, x_center + line_step * 4, y_start, color);
  174.   display.drawLine(x_center - line_step * 2, y_start + step_size, x_center + line_step * 2, y_start + step_size, color);
  175.   display.drawLine(x_center - line_step * 2, y_end - step_size, x_center + line_step * 2, y_end - step_size, color);
  176.   display.drawLine(x_center - line_step * 4, y_end, x_center + line_step * 4, y_end, color);
  177.   for (uint16_t y_current = y_start + 2 * step_size; y_current < y_end - 2 * step_size; y_current += step_size) {
  178.     display.drawLine(x_center - line_step, y_current, x_center + line_step, y_current, color);
  179.   }
  180. }
  181.  
  182. void drawSineWave(uint16_t x, uint16_t y, uint16_t width, uint16_t height, float amplitude, float frequency, float phase, uint16_t color) {
  183.   //  amplitude: vertical compression (1 = screen height)
  184.   //  frequency: horizontal compression (1 = screen width)
  185.   //  phase: horitontal shift (in degrees)
  186.  
  187.   uint16_t vTop =  y, vCenter = y + height / 2, vBottom = y + height - 1  , step_size = 2;
  188.   int old_x = x, old_y = vCenter, new_y = old_y;
  189.  
  190.   for (int new_x = x; new_x < x + width; new_x += step_size) {
  191.     float value = amplitude * sin((frequency * M_PI / 180 * new_x) + phase);
  192.     new_y = vCenter + value * (height / 2) ;
  193.     new_y = min(max(new_y, vTop), vBottom);
  194.  
  195.     if (new_x == x) {
  196.       display.drawPixel(new_x, new_y, color);
  197.     } else {
  198.       display.drawLine(old_x, old_y, new_x, new_y, color);
  199.       display.drawLine(old_x + 1, old_y - 1, new_x + 1, new_y - 1, color);
  200.     }
  201.  
  202.     old_x = new_x;
  203.     old_y = new_y;
  204.   }
  205. }
  206.  
  207. void drawCompositeWave(uint16_t x, uint16_t y, uint16_t width, uint16_t height, float amplitude1, float frequency1, float amplitude2, float frequency2, float amplitude3, float frequency3, uint16_t phase, uint16_t color) {
  208.   //  amplitude: vertical compression (1 = height)
  209.   //  frequency: horizontal compression (1 = width)
  210.   //  phase: horitontal shift (in degrees)
  211.  
  212.   uint16_t vTop =  y, vCenter = y + height / 2, vBottom = y + height - 1  , step_size = 2;
  213.   int old_x = x, old_y = vCenter, new_y = old_y;
  214.  
  215.   for (int new_x = x; new_x < x + width; new_x += step_size) {
  216.     float value1 = amplitude1 * sin((frequency1 * M_PI / 180 * new_x) + phase);
  217.     float value2 = amplitude2 * cos((frequency2 * M_PI / 180 * new_x) + phase);
  218.     float value3 = amplitude3 * tan((frequency3 * M_PI / 180 * new_x) + phase);
  219.     float value = value1 * value2 * value3 * 0.66;
  220.     new_y = vCenter + value * (height / 2) ;
  221.     new_y = min(max(new_y, vTop), vBottom);
  222.  
  223.     if (new_x == x) {
  224.       display.drawPixel(new_x, new_y, color);
  225.     } else {
  226.       display.drawLine(old_x, old_y, new_x, new_y, color);
  227.       display.drawLine(old_x + 1, old_y - 1, new_x + 1, new_y - 1, color);
  228.     }
  229.  
  230.     old_x = new_x;
  231.     old_y = new_y;
  232.   }
  233. }
  234.  
  235. void drawCircularGauge(uint16_t x, uint16_t y, uint16_t width, uint16_t height, int line_width, int start_angle, float percentage, uint16_t color) {
  236.   int radius_x = width / 2,
  237.       radius_y = height / 2,
  238.       x_center = x + radius_x,
  239.       y_center = y + radius_y;
  240.   float DEG2RAD = 0.0174532925;
  241.   byte seg_degrees = 6;
  242.   int seg_count = map(percentage, 0, 100, 0, 360) / seg_degrees;
  243.  
  244.   // Calculate first pair of coordinates for segment start
  245.   float start_x = cos((start_angle - 90) * DEG2RAD);
  246.   float start_y = sin((start_angle - 90) * DEG2RAD);
  247.   uint16_t x0 = start_x * (radius_x - line_width) + x_center;
  248.   uint16_t y0 = start_y * (radius_y - line_width) + y_center;
  249.   uint16_t x1 = start_x * radius_x + x_center;
  250.   uint16_t y1 = start_y * radius_y + y_center;
  251.  
  252.   display.fillRect(x, y, width, height, BLACK); // Reset the display area's background
  253.  
  254.   for (int current_angle = start_angle; current_angle < start_angle + seg_degrees * seg_count; current_angle += seg_degrees) {
  255.     float start_x2 = cos((current_angle + 1 - 90) * DEG2RAD);
  256.     float start_y2 = sin((current_angle + 1 - 90) * DEG2RAD);
  257.     int x2 = start_x2 * (radius_x - line_width) + x_center;
  258.     int y2 = start_y2 * (radius_y - line_width) + y_center;
  259.     int x3 = start_x2 * radius_x + x_center;
  260.     int y3 = start_y2 * radius_y + y_center;
  261.  
  262.     display.fillTriangle(x0, y0, x1, y1, x2, y2, color);
  263.     display.fillTriangle(x1, y1, x2, y2, x3, y3, color);
  264.  
  265.     // Copy segment end to segement start for next segment
  266.     x0 = x2;
  267.     y0 = y2;
  268.     x1 = x3;
  269.     y1 = y3;
  270.   }
  271. }
  272.  
  273. void drawHorizontalTriangleGauge(uint16_t x0, uint16_t y0, uint16_t width, uint16_t height, uint16_t color_frame, uint16_t color_fill, float percentage) {
  274.   uint16_t width_filled = map(percentage, 0, 100, 0, width - 2),
  275.            x1 = x0,
  276.            y1 = y0 + height - 1,
  277.            x2 = x0 + width - 1,
  278.            y2 = y1;
  279.  
  280.   display.fillRect(x0, y0, width, height, BLACK); // Reset the display area's background
  281.   display.fillRect(x0 + 1, y0, width_filled, height - 1, color_fill);
  282.   display.fillTriangle(x0, y0, x2, y0, x0, y1 - 1, BLACK);
  283.   display.drawTriangle(x0, y1, x2, y0, x2, y2, color_frame);
  284. }
  285.  
  286. void drawVerticalTriangleGauge(uint16_t x0, uint16_t y0, uint16_t width, uint16_t height, uint16_t color_frame, uint16_t color_fill, float percentage) {
  287.   uint16_t height_empty = map(percentage, 0, 100, height - 2, 0),
  288.            x1 = x0,
  289.            y1 = y0 + height - 1,
  290.            x2 = x0 + width - 1,
  291.            y2 = y1;
  292.  
  293.   display.fillRect(x0, y0, width, height, BLACK); // Reset the display area's background
  294.   display.fillTriangle(x0, y0, x2, y0, x0, y2, color_fill);
  295.   display.fillRect(x0 + 1, y0 + 1, width - 2, height_empty, BLACK);
  296.   display.drawTriangle(x0, y0, x2, y0, x0, y2, color_frame);
  297.   display.drawLine(x0, y2, x2, y0, color_frame);
  298. }
  299.  
  300. void drawVerticalRandomBarChart(uint16_t x0, uint16_t y0, uint16_t width, uint16_t height, uint16_t bar_width, uint16_t bar_spacing, uint16_t color) {
  301.   display.fillRect(x0, y0, width, height, BLACK); // Reset the display area's background
  302.   display.drawLine(x0, y0, x0, y0 + height - 1, color);
  303.   display.drawLine(x0, y0 + height - 1, x0 + width - 1, y0 + height - 1, color);
  304.  
  305.   for (int x1 = x0 + bar_spacing; x1 < width - bar_spacing; x1 += (bar_width + bar_spacing)) {
  306.     int bar_height = random(0, height);
  307.     display.fillRect(x1, y0 + height - bar_height, bar_width, bar_height, color);
  308.   }
  309. }
  310.  
  311. void drawHorizontalRandomBarChart(uint16_t x0, uint16_t y0, uint16_t width, uint16_t height, uint16_t bar_height, uint16_t bar_spacing, uint16_t color) {
  312.   display.fillRect(x0, y0, width, height, BLACK); // Reset the display area's background
  313.   display.drawLine(x0, y0, x0, y0 + height - 1, color);
  314.   display.drawLine(x0, y0 + height - 1, x0 + width - 1, y0 + height - 1, color);
  315.  
  316.   for (int y1 = (y0 + bar_spacing); y1 < (y0 + height); y1 += (bar_height + bar_spacing)) {
  317.     int bar_width = random(0, width);
  318.     display.fillRect(x0, y1, bar_width, bar_height, color);
  319.   }
  320. }
  321.  
  322. #define BUFFPIXEL 20 //Printing speed 20 is meant to be the best, you can go to 60 but using too much RAM
  323.  
  324. //drawing function no touchy :D
  325. void bmpDraw(char *filename, int x, int y) {
  326.  
  327.   File bmpFile;
  328.   int bmpWidth, bmpHeight;            // W+H in pixels
  329.   uint8_t bmpDepth;                   // Bit depth (currently must be 24)
  330.   uint32_t bmpImageoffset;            // Start of image data in file
  331.   uint32_t rowSize;                   // Not always = bmpWidth; may have padding
  332.   uint8_t sdbuffer[3 * BUFFPIXEL];    // pixel in buffer (R+G+B per pixel)
  333.   uint16_t lcdbuffer[BUFFPIXEL];      // pixel out buffer (16-bit per pixel)
  334.   uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer
  335.   boolean goodBmp = false;            // Set to true on valid header parse
  336.   boolean flip = true;                // BMP is stored bottom-to-top
  337.   int w, h, row, col;
  338.   uint8_t r, g, b;
  339.   uint32_t pos = 0, startTime = millis();
  340.   uint8_t lcdidx = 0;
  341.   boolean first = true;
  342.  
  343.   if ((x >= display.width()) || (y >= display.height()))
  344.     return;
  345.  
  346.   Serial.println();
  347.   progmemPrint(PSTR("Loading image '"));
  348.   Serial.print(filename);
  349.   Serial.println('\'');
  350.   // Open requested file on SD card
  351.   if ((bmpFile = SD.open(filename)) == NULL) {
  352.     progmemPrintln(PSTR("File not found"));
  353.     return;
  354.   }
  355.  
  356.   // Parse BMP header
  357.   if (read16(bmpFile) == 0x4D42) { // BMP signature
  358.     progmemPrint(PSTR("File size: "));
  359.     Serial.println(read32(bmpFile));
  360.     (void)read32(bmpFile);            // Read & ignore creator bytes
  361.     bmpImageoffset = read32(bmpFile); // Start of image data
  362.     progmemPrint(PSTR("Image Offset: "));
  363.     Serial.println(bmpImageoffset, DEC);
  364.     // Read DIB header
  365.     progmemPrint(PSTR("Header size: "));
  366.     Serial.println(read32(bmpFile));
  367.     bmpWidth = read32(bmpFile);
  368.     bmpHeight = read32(bmpFile);
  369.     if (read16(bmpFile) == 1) {   // # planes -- must be '1'
  370.       bmpDepth = read16(bmpFile); // bits per pixel
  371.       progmemPrint(PSTR("Bit Depth: "));
  372.       Serial.println(bmpDepth);
  373.       if ((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed
  374.  
  375.         goodBmp = true; // Supported BMP format -- proceed!
  376.         progmemPrint(PSTR("Image size: "));
  377.         Serial.print(bmpWidth);
  378.         Serial.print('x');
  379.         Serial.println(bmpHeight);
  380.  
  381.         // BMP rows are padded (if needed) to 4-byte boundary
  382.         rowSize = (bmpWidth * 3 + 3) & ~3;
  383.  
  384.         // If bmpHeight is negative, image is in top-down order.
  385.         // This is not canon but has been observed in the wild.
  386.         if (bmpHeight < 0) {
  387.           bmpHeight = -bmpHeight;
  388.           flip = false;
  389.         }
  390.  
  391.         // Crop area to be loaded
  392.         w = bmpWidth;
  393.         h = bmpHeight;
  394.         if ((x + w - 1) >= display.width())
  395.           w = display.width() - x;
  396.         if ((y + h - 1) >= display.height())
  397.           h = display.height() - y;
  398.  
  399.         // Set TFT address window to clipped image bounds
  400.         display.setAddrWindow(x, y, x + w - 1, y + h - 1);
  401.  
  402.         for (row = 0; row < h; row++) { // For each scanline...
  403.           // Seek to start of scan line.  It might seem labor-
  404.           // intensive to be doing this on every line, but this
  405.           // method covers a lot of gritty details like cropping
  406.           // and scanline padding.  Also, the seek only takes
  407.           // place if the file position actually needs to change
  408.           // (avoids a lot of cluster math in SD library).
  409.           if (flip) // Bitmap is stored bottom-to-top order (normal BMP)
  410.             pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
  411.           else // Bitmap is stored top-to-bottom
  412.             pos = bmpImageoffset + row * rowSize;
  413.           if (bmpFile.position() != pos) { // Need seek?
  414.             bmpFile.seek(pos);
  415.             buffidx = sizeof(sdbuffer); // Force buffer reload
  416.           }
  417.  
  418.           for (col = 0; col < w; col++) { // For each column...
  419.             // Time to read more pixel data?
  420.             if (buffidx >= sizeof(sdbuffer)) { // Indeed
  421.               // Push LCD buffer to the display first
  422.               if (lcdidx > 0) {
  423.                 display.pushColors(lcdbuffer, lcdidx, first);
  424.                 lcdidx = 0;
  425.                 first = false;
  426.               }
  427.               bmpFile.read(sdbuffer, sizeof(sdbuffer));
  428.               buffidx = 0; // Set index to beginning
  429.             }
  430.  
  431.             // Convert pixel from BMP to TFT format
  432.             b = sdbuffer[buffidx++];
  433.             g = sdbuffer[buffidx++];
  434.             r = sdbuffer[buffidx++];
  435.             lcdbuffer[lcdidx++] = display.color565(r, g, b);
  436.           } // end pixel
  437.         }   // end scanline
  438.         // Write any remaining data to LCD
  439.         if (lcdidx > 0) {
  440.           display.pushColors(lcdbuffer, lcdidx, first);
  441.         }
  442.         progmemPrint(PSTR("Loaded in "));
  443.         Serial.print(millis() - startTime);
  444.         Serial.println(" ms");
  445.       } // end goodBmp
  446.     }
  447.   }
  448.  
  449.   bmpFile.close();
  450.   if (!goodBmp)
  451.     progmemPrintln(PSTR("BMP format not recognized."));
  452. }
  453.  
  454. // These read 16- and 32-bit types from the SD card file.
  455. // BMP data is stored little-endian, Arduino is little-endian too.
  456. // May need to reverse subscript order if porting elsewhere.
  457.  
  458. uint16_t read16(File f) {
  459.   uint16_t result;
  460.   ((uint8_t *)&result)[0] = f.read(); // LSB
  461.   ((uint8_t *)&result)[1] = f.read(); // MSB
  462.   return result;
  463. }
  464.  
  465. uint32_t read32(File f) {
  466.   uint32_t result;
  467.   ((uint8_t *)&result)[0] = f.read(); // LSB
  468.   ((uint8_t *)&result)[1] = f.read();
  469.   ((uint8_t *)&result)[2] = f.read();
  470.   ((uint8_t *)&result)[3] = f.read(); // MSB
  471.   return result;
  472. }
  473.  
  474. // Copy string from flash to serial port
  475. // Source string MUST be inside a PSTR() declaration!
  476. void progmemPrint(const char *str) {
  477.   char c;
  478.   while (c = pgm_read_byte(str++))
  479.     Serial.print(c);
  480. }
  481.  
  482. // Same as above, with trailing newline
  483. void progmemPrintln(const char *str) {
  484.   progmemPrint(str);
  485.   Serial.println();
  486. }
RAW Paste Data