Author Topic: Scrolling LED Sign  (Read 4751 times)

0 Members and 1 Guest are viewing this topic.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Scrolling LED Sign
« on: August 22, 2018, 02:43:31 am »
I've been going through all my code snippets to organize them. I ran across this one and thought others might like it. It's a very simple method for creating a scrolling sign of any size.

Code: QB64: [Select]
  1. '********************************
  2. '*                              *
  3. '* LED Maker  by  Terry Ritchie *
  4. '*                              *
  5. '********************************
  6.  
  7. CONST ROUND = 0, SQUARE = 1
  8.  
  9. TYPE LED
  10.     Screen AS LONG ' the LED screen to show on screen
  11.     Image AS LONG '  the LED image to work on in the background
  12.     Mask AS LONG '   the LED mask to place over the LED image
  13.  
  14. DIM LED AS LED
  15. DIM News$
  16. DIM Mpos%
  17.  
  18. News$ = "                Breaking News!                QB64.org is awesome! "
  19.  
  20. MAKELED 128, 16, 10, ROUND '                                                   create LED screen
  21. SCREEN LED.Screen '                                                            set LED screen as view screen
  22. _TITLE "LED Scrolling Sign" '                                                  give screen a title
  23. Mpos% = 0 '                                                                    reset message position pointer
  24.     _LIMIT 5 '                                                                 5 frames per second
  25.     _DEST LED.Image '                                                          set small image as destination
  26.     COLOR _RGB32(255, 255, 0) '                                                set text color to yellow
  27.     Mpos% = Mpos% + 1 '                                                        increment message pointer
  28.     IF Mpos% > LEN(News$) THEN Mpos% = 1 '                                     reset pointer at end of message
  29.     LOCATE 1, 1 '                                                              position cursor
  30.     PRINT MID$(News$, Mpos%, 16); '                                            display portion of message
  31.     _DEST 0 '                                                                  set LED screen back to destination
  32.     _PUTIMAGE , LED.Image '                                                    stretch the small image across screen
  33.     _PUTIMAGE , LED.Mask '                                                     place LED mask over image
  34.     _DISPLAY '                                                                 viola', the screen looks pixelized
  35.  
  36. '----------------------------------------------------------------------------------------------------------------------
  37. '                                                                                                               MAKELED
  38. SUB MAKELED (w%, h%, psize%, pshape%)
  39.  
  40. SHARED LED AS LED '  need access to LED screen properties
  41.  
  42. DIM OriginalDest& '  calling routine destination
  43. DIM LEDPixel& '      temporary image to hold single LED pixel
  44.  
  45. OriginalDest& = _DEST '                                                        remember calling routine destination
  46. LED.Screen = _NEWIMAGE(w% * psize%, h% * psize%, 32) '                         create LED screen image holder
  47. LED.Image = _NEWIMAGE(w%, h%, 32) '                                            create LED work image
  48. LED.Mask = _COPYIMAGE(LED.Screen) '                                            create LED matrix image mask
  49. LEDPixel& = _NEWIMAGE(psize%, psize%, 32) '                                    create LED pixel
  50. _DEST LEDPixel& '                                                              set LED pixel as destination image
  51. CLS '                                                                          remove 0,0,0 alpha transparency
  52. LINE (0, 0)-(psize% - 1, psize% - 1), _RGB32(10, 10, 10), BF '                 set background color
  53. SELECT CASE pshape% '                                                          which pixel shape should be created?
  54.     CASE ROUND '                                                               round pixels
  55.         CIRCLE (psize% \ 2, psize% \ 2), psize% \ 2 - 1, _RGB32(0, 0, 2) '     create round pixel in center of image
  56.         PAINT (psize% \ 2, psize% \ 2), _RGB32(0, 0, 1), _RGB32(0, 0, 2) '     fill the pixel in
  57.     CASE SQUARE '                                                              square pixels
  58.         LINE (1, 1)-(psize% - 1, psize% - 1), _RGB32(0, 0, 2), B '            create square pixel in center of image
  59.         LINE (2, 2)-(psize% - 2, psize% - 2), _RGB32(0, 0, 1), BF
  60. _DEST LED.Mask '                                                               set LED mask as destination image
  61. CLS '                                                                          remove 0,0,0 alpha transparency
  62. FOR x% = 0 TO w% * psize% - 1 STEP psize% '                                    cycle through horizontal pixel positions
  63.     FOR y% = 0 TO h% * psize% - 1 STEP psize% '                                cycle through vertical pixel positions
  64.         _PUTIMAGE (x%, y%), LEDPixel& '                                        place a pixel image
  65.     NEXT y%
  66. NEXT x%
  67. FOR x% = 0 TO w% * psize% - 1 STEP psize% * 8 '                                cycle every 8 horizontal pixels
  68.     LINE (x%, 0)-(x%, h% * psize% - 1), _RGB32(0, 0, 0) '                      draw a divider line
  69. NEXT x%
  70. FOR y% = 0 TO h% * psize% - 1 STEP psize% * 8 '                                cycle every 8 vertical pixels
  71.     LINE (0, y%)-(w% * psize% - 1, y%), _RGB32(0, 0, 0) '                      draw a divider line
  72. NEXT y%
  73. _SETALPHA 0, _RGB32(0, 0, 1) '                                                 set transparency color of mask
  74. _SETALPHA 63, _RGB32(0, 0, 2)
  75. _DEST OriginalDest& '                                                          return to calling routine destination
  76. _FREEIMAGE LEDPixel& '                                                         removel pixel image from memory
  77.  
  78.  
  79. '----------------------------------------------------------------------------------------------------------------------
  80.  
In order to understand recursion, one must first understand recursion.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Scrolling LED Sign
« Reply #1 on: August 22, 2018, 03:00:17 am »
This bring back memories! Cool...
Logic is the beginning of wisdom.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Scrolling LED Sign
« Reply #2 on: August 27, 2018, 02:44:42 pm »
Hi [banned user],

Your code work not, because PIXEL type is not defined.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Scrolling LED Sign
« Reply #3 on: August 27, 2018, 03:36:46 pm »
Hi Petr,

Just comment it out and lower limit from 60 to say 4, otherwise it zips by! ;)