Author Topic: Building a Scrolling LED Screen  (Read 2930 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Building a Scrolling LED Screen
« on: May 08, 2021, 11:54:57 pm »
A quick 100 lines or so to show 3 basic steps:
Code: QB64: [Select]
  1. _Title "Building a Scrolling LED Screen" ' b+ 2021-05-08
  2. Screen _NewImage(1200, 160, 32)
  3. _Delay .25 'give screen time to load
  4. _ScreenMove _Middle 'and center screen
  5.  
  6. 'scroll some text
  7. Text$ = "Try scrolling me for awhile until you got it, then press a key...   "
  8. lenText = Len(Text$)
  9. startTextPos = 1
  10. 'put text in sign 15 chars wide in middle of screen print the message moving down 1 character evey frame
  11. _Title "Building a Scrolling LED Screen:  Step 1 get some code to scroll your message in middle of screen."
  12.     k$ = InKey$
  13.     Cls
  14.     ' two pieces of text?  when get to end of text will have less than 15 chars to fill sign so get remainder from front
  15.     len1 = lenText - startTextPos
  16.     If len1 < 15 Then len2 = 15 - len1 Else len1 = 15: len2 = 0
  17.     ' locate at middle of screen for 15 char long sign
  18.     _PrintString ((1200 - 15 * 8) / 2, (160 / 2) - 8), Mid$(Text$, startTextPos, len1) + Mid$(Text$, 1, len2)
  19.     startTextPos = startTextPos + 1
  20.     If startTextPos > lenText Then startTextPos = 1
  21.     _Display ' no blinking when clear screen so often
  22.     _Limit 5 ' slow down to see scroll
  23.  
  24. ' OK   now for the enLARGE M E N T   using _PutImage
  25. ' our little sign is 16 pixels high and 8 * 15 chars pixels wide = 120
  26. Dim sign As Long
  27. sign = _NewImage(120, 16, 32) ' we will store the print image here
  28.  
  29. '  _PUTIMAGE [STEP] [(dx1, dy1)-[STEP][(dx2, dy2)]][, sourceHandle&][, destHandle&][, ][STEP][(sx1, sy1)[-STEP][(sx2, sy2)]][_SMOOTH]
  30. '  use same pixel location to _printString as for _PutImage Source rectangle ie (sx1, sy1), -step( sign width and height)
  31.  
  32. ' test screen capture with _putimage and then blowup with _putimage
  33. '_PutImage , 0, sign, ((1200 - 15 * 8) / 2, (160 / 2) - 8)-Step(119, 15)
  34. 'Cls
  35. '_PutImage , sign, 0 ' stretch to whole screen
  36. '_Display
  37.  
  38. 'now that that works  do it on the move
  39.  
  40. ' about here I resized the screen to 1200 x 160 to make the text scalable X's 10 ie 120 x 10 wide and 16 x 10 high
  41. _Title "Building a Scrolling LED Screen:  Step 2 Blow it up by using _PutImage twice once to capture, then to expand"
  42. k$ = ""
  43.     k$ = InKey$
  44.     Cls
  45.     ' two pieces of text?  when get to end of text will have less than 15 chars to fill sign so get remainder from front
  46.     len1 = lenText - startTextPos
  47.     If len1 < 15 Then len2 = 15 - len1 Else len1 = 15: len2 = 0
  48.     ' locate at middle of screen for 15 char long sign
  49.     _PrintString ((1200 - 15 * 8) / 2, (160 / 2) - 8), Mid$(Text$, startTextPos, len1) + Mid$(Text$, 1, len2)
  50.     _PutImage , 0, sign, ((1200 - 15 * 8) / 2, (160 / 2) - 8)-Step(119, 15)
  51.  
  52.     Cls
  53.     _PutImage , sign, 0 ' stretch to whole screen
  54.     _Display ' no blinking when clear screen so often
  55.     _Limit 5 ' slow down to see scroll
  56.     startTextPos = startTextPos + 1
  57.     If startTextPos > lenText Then startTextPos = 1
  58.  
  59.  
  60.  
  61. ' now for a mask just draw a grid  test grid draw here
  62. 'For x = 0 To _Width Step 10 ' verticals
  63. '    Line (x, 0)-(x + 3, _Height), &HFF000000, BF
  64. 'Next
  65. 'For y = 0 To _Height Step 10
  66. '    Line (0, y)-(_Width, y + 3), &HFF000000, BF
  67. 'Next
  68.  
  69.  
  70.  
  71. _Title "Building a Scrolling LED Screen:  Step 3 Mask or Cover the thing with a grid or grate."
  72. ' here is the whole code not including all setup variables from above
  73. k$ = ""
  74.     k$ = InKey$
  75.     Cls
  76.     ' two pieces of text?  when get to end of text will have less than 15 chars to fill sign so get remainder from front
  77.     len1 = lenText - startTextPos
  78.     If len1 < 15 Then len2 = 15 - len1 Else len1 = 15: len2 = 0
  79.     ' locate at middle of screen for 15 char long sign
  80.     _PrintString ((1200 - 15 * 8) / 2, (160 / 2) - 8), Mid$(Text$, startTextPos, len1) + Mid$(Text$, 1, len2)
  81.     _PutImage , 0, sign, ((1200 - 15 * 8) / 2, (160 / 2) - 8)-Step(119, 15)
  82.  
  83.     Cls
  84.     _PutImage , sign, 0 ' stretch to whole screen
  85.  
  86.     ' now for a mask just draw a grid  best to draw this and copy and layover screen as another layer
  87.     ' here QB64 is fast evough to redarw each time
  88.     For x = 0 To _Width Step 10 ' verticals
  89.         Line (x, 0)-(x + 3, _Height), &HFF000000, BF
  90.     Next
  91.     For y = 0 To _Height Step 10
  92.         Line (0, y)-(_Width, y + 3), &HFF000000, BF
  93.     Next
  94.  
  95.     _Display ' no blinking when clear screen so often
  96.     _Limit 5 ' slow down to see scroll
  97.     startTextPos = startTextPos + 1
  98.     If startTextPos > lenText Then startTextPos = 1
  99.  
  100.  
« Last Edit: May 09, 2021, 12:09:58 am by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Building a Scrolling LED Screen
« Reply #1 on: May 09, 2021, 06:34:51 am »
Very cool indeed.... Thank you for sharing...
Logic is the beginning of wisdom.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Building a Scrolling LED Screen
« Reply #2 on: May 09, 2021, 12:02:33 pm »
@bplus
good job! It is a fine approach to the task of LED scrolling screen.
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Building a Scrolling LED Screen
« Reply #3 on: May 09, 2021, 02:35:04 pm »
Thanks I hope it helps introduce _PUTIMAGE and using _NEWIMAGE to store an image.

_PUTIMAGE is extremely complex but man! once you master it!!!

I still have to pull a copy of the complete syntax from Help for reference as I showed in code.