AntonioVillanueva

Text c scroll in c with rpi-rgb-led-matrix and P10 64x64

Dec 18th, 2020 (edited)
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.62 KB | None | 0 0
  1. /* Text c scroll in c with  rpi-rgb-led-matrix   and P10 64x64 A.Villanueva  
  2.  * https://github.com/hzeller/rpi-rgb-led-matrix
  3.  *- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
  4.  *
  5.  * Using the C-API of this library.
  6.  *
  7.  */
  8. #include "led-matrix-c.h"
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <unistd.h>
  13.  
  14. int main(int argc, char **argv) {
  15.   struct RGBLedMatrixOptions options;
  16.   struct RGBLedMatrix *matrix;
  17.   struct LedCanvas *offscreen_canvas;
  18.   const char FONT[] ="../fonts/texgyre-27.bdf";
  19.   const char *message="HOLA COMO ESTAS ";  
  20.   uint8_t r=0,g=255,b=0;//Color RGB
  21.   int width, height;
  22.   int x=128, y=32, i;
  23.  
  24.   memset(&options, 0, sizeof(options));
  25.   options.rows = 64;
  26.   options.cols =64;
  27.   options.chain_length = 6;
  28.  
  29.   /* This supports all the led commandline options. Try --led-help */
  30.   matrix = led_matrix_create_from_options(&options, &argc, &argv);
  31.   if (matrix == NULL)
  32.     return 1;
  33.  
  34.   /* Let's do an example with double-buffering. We create one extra
  35.    * buffer onto which we draw, which is then swapped on each refresh.
  36.    * This is typically a good aproach for animations and such.
  37.    */
  38.   offscreen_canvas = led_matrix_create_offscreen_canvas(matrix);
  39.  
  40.   led_canvas_get_size(offscreen_canvas, &width, &height);
  41.  
  42.   fprintf(stderr, "Size: %dx%d. Hardware gpio mapping: %s\n",
  43.           width, height, options.hardware_mapping);
  44.          
  45.  
  46. // Draw text, a standard NUL terminated C-string encoded in UTF-8,
  47. // with given "font" at "x","y" with "color".
  48. // Draw text as above, but vertically (top down).
  49. // The text is a standard NUL terminated C-string encoded in UTF-8.
  50. // "font, "x", "y", "color" and "background_color" are same as DrawText().
  51. // "kerning_offset" allows for additional spacing between characters (can be
  52. // negative).
  53. // Returns font height to advance up on the screen.
  54. //int vertical_draw_text(struct LedCanvas *c, struct LedFont *font, int x, int y,
  55. //                       uint8_t r, uint8_t g, uint8_t b,
  56. //                       const char *utf8_text, int kerning_offset = 0)
  57.        
  58.     for (int temp=0;temp<1000;temp++){  
  59.          
  60.  
  61.     printf ("how many pixels we advanced on the screen = %d \n",draw_text( offscreen_canvas,load_font(FONT), x, y,r,g,b ,message,0));  
  62.      
  63.      
  64.     /* Now, we swap the canvas. We give swap_on_vsync the buffer we
  65.      * just have drawn into, and wait until the next vsync happens.
  66.      * we get back the unused buffer to which we'll draw in the next
  67.      * iteration.
  68.      */
  69.     offscreen_canvas = led_matrix_swap_on_vsync(matrix, offscreen_canvas);          
  70.   }
  71.   led_matrix_delete(matrix);
  72.  
  73.   return 0;
  74. }
Add Comment
Please, Sign In to add comment