Jump to content

how to do a LED Panel ?


Gianni
 Share

Go to solution Solved by UEZ,

Recommended Posts

Hi
I would like to build a virtual led panel, but I don't know which "material" to use to build the leds
in this rudimental attempt I used an "GUICtrlCreateLabel" for each led,

and used "GUICtrlSetBkColor" to change it's color.

I am sure that an graphic expert could drive me in a better solution.

The leds should be resizeable
I post this attempt here just to show (more or less) what I would achieve
any help and advise is welcome
thanks

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
; #include "Font.au3"
Global $Font
Font()
Local $pixX = 13 ;  pixel width
Local $pixY = 13 ;  pixel height
Local $space = 1 ;  space between pixels
Local $PixelvBars = 50 ;    how many vertical bars
; Local $LeftOffset = 0 ;       distance from the left side of window
; Local $TopOffset = 0 ;        distance from the top of window
Local $PanelWidth = (($pixX + $space) * $PixelvBars) + 1 ; + ($LeftOffset + 8)
Local $PanelHeight = (($pixY + $space) * 7) + 1; + ($TopOffset + 8)
Local $Pixel[2][8][$PixelvBars + 2]
Local $x, $y
Global $Pix_Off = "0x550000" ; dark red
Global $Pix_On = "0xff0000" ; light red

; Create Panel
$Panel = GUICreate("", $PanelWidth, $PanelHeight, 300, 300, 0x80800000, 0x00000008)
GUISetBkColor(0x6f0000, $Panel) ; Background color of window
For $x = 1 To $PixelvBars
    For $y = 1 To 7
        $Pixel[0][$y][$x] = GUICtrlCreateLabel("", $x * ($pixX + $space) - $pixX, $y * ($pixY + $space) - $pixY, $pixX, $pixY)
        GUICtrlSetBkColor(-1, 0x550000) ; color of the pixel
        $Pixel[1][$y][$x] = $Pix_Off
    Next
Next
For $y = 1 To 7
    $Pixel[1][$y][$PixelvBars + 1] = $Pix_Off
Next
GUISetState(@SW_SHOW, $Panel)

; While 1 ; -----------------------------------------
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $GUI_EVENT_CLOSE
        Exit
EndSwitch
$msg = "  I LIKE THIS, BUT NOT SO MUCH... 1 2 3   " & @HOUR & ":" & @MIN
For $z = 1 To StringLen($msg)
    $chr = Asc(StringMid($msg, $z, 1)) - 32
    If $chr < 0 Then $chr = 0
    If $chr > 77 Then $chr = 77
    Print($chr)
Next

;  RandomBar()
; Print()
; MsgBox("","","")
For $i = 1 To $PixelvBars - 2
    ROL()
Next
; Sleep(3000)
; Effects
$Timer = TimerInit()
While TimerDiff($Timer) < 3000 ; repeat this for 3 seconds
    RandomPix()
WEnd
$Timer = TimerInit()
While TimerDiff($Timer) < 3000
    RandomBar()
WEnd
$Timer = TimerInit()
While TimerDiff($Timer) < 3000
    RandomBaW()
WEnd

; WEnd ; --------------------------------------------
; functions
; - - - - - rotation - - - - -
Func ROL() ; rotate left
    For $x = 1 To $PixelvBars
        For $y = 1 To 7
            $Pixel[1][$y][$x] = $Pixel[1][$y][$x + 1]
            GUICtrlSetBkColor($Pixel[0][$y][$x], $Pixel[1][$y][$x]) ; color of the pixel
        Next
    Next
EndFunc   ;==>ROL

; effects
Func RandomPix()
    For $x = 1 To $PixelvBars
        For $y = 1 To 7
            $rgb = "0x" & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2)
            GUICtrlSetBkColor($Pixel[0][$y][$x], $rgb) ; color of the pixel
            $Pixel[1][$y][$x] = $rgb
        Next
    Next
EndFunc   ;==>RandomPix

Func RandomBar()
    For $x = 1 To $PixelvBars
        $rgb = "0x" & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2)
        For $y = 1 To 7
            GUICtrlSetBkColor($Pixel[0][$y][$x], $rgb) ; color of the pixel
            $Pixel[1][$y][$x] = $rgb
        Next
    Next
EndFunc   ;==>RandomBar

Func RandomBaW() ; Black & White snow effect
    For $x = 1 To $PixelvBars
        For $y = 1 To 7
            Local $color = Hex(Random(0, 255, 1), 2)
            $rgb = "0x" & $color & $color & $color
            GUICtrlSetBkColor($Pixel[0][$y][$x], $rgb) ; color of the pixel
            $Pixel[1][$y][$x] = $rgb
        Next
    Next
EndFunc   ;==>RandomBaW
Func Print($msg)
    For $i = 1 To 7
        If $Font[$msg][$i - 1] <> "" Then
            For $ii = 0 To 6
                If StringMid($Font[$msg][$i - 1], $ii + 1, 1) = "0" Then
                    $rgb = $Pix_Off
                Else
                    $rgb = $Pix_On
                EndIf
                GUICtrlSetBkColor($Pixel[0][$ii + 1][$PixelvBars], $rgb) ; color of the pixel
                $Pixel[1][$ii + 1][$PixelvBars] = $rgb ; color of the pixel
            Next
        Else
            ROL()
            Return
        EndIf
        ROL()
        ; Sleep(1000)
    Next
EndFunc   ;==>Print

Func Font() ; still incomplete
    Dim $Font[64][7] = _
            [["0000000", "0000000", "0000000", "0000000"], _            ;   SPACE
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE !
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE "
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE #
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE $
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE %
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE &
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE '
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE (
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE )
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE *
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE +
            ["0000001", "0000010", "0000000"], _                        ;   ,
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE -
            ["0000000", "0000001", "0000000", "0000000", "0000000"], _  ;   PERIOD .
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE /
            ["0111110", "1000001", "1000001", "1000001", "0111110"], _  ;   0
            ["0100001", "1111111", "0000001"], _                        ;   1
            ["0100011", "1000101", "1001001", "1001001", "0110001"], _  ;   2
            ["0100010", "1001001", "1001001", "1001001", "0110110"], _  ;   3
            ["0001000", "0011000", "0101000", "1111111", "0001000"], _  ;   4
            ["1111001", "1001001", "1001001", "1001001", "1000110"], _  ;   5
            ["0111110", "1001001", "1001001", "1001001", "0100110"], _  ;   6
            ["1000011", "1000100", "1001000", "1110000"], _             ;   7
            ["0110110", "1001001", "1001001", "1001001", "0110110"], _  ;   8
            ["0110010", "1001001", "1001001", "1001001", "0111110"], _  ;   9
            ["0000000", "0100010", "0000000"], _    ;   :
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE ;
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE <
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE =
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE >
            ["0100000", "1000000", "1001101", "1001000", "0110000"], _  ;   ?
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE @
            ["0111111", "1001000", "1001000", "1001000", "0111111"], _  ;   A
            ["1111111", "1001001", "1001001", "1001001", "0110110"], _  ;   B
            ["0111110", "1000001", "1000001", "1000001", "0100010"], _  ;   C
            ["1111111", "1000001", "1000001", "1000001", "0111110"], _  ;   D
            ["1111111", "1001001", "1001001", "1001001"], _             ;   E
            ["1111111", "1001000", "1001000", "1001000"], _             ;   F
            ["0111110", "1000001", "1000001", "1001001", "0101110"], _  ;   G
            ["1111111", "0001000", "0001000", "0001000", "1111111"], _  ;   H
            ["1000001", "1111111", "1000001"], _                        ;   I
            ["0000110", "0000001", "0000001", "0000001", "1111110"], _  ;   J
            ["1111111", "0001000", "0010100", "0100010", "1000001"], _  ;   K
            ["1111111", "0000001", "0000001", "0000001"], _             ;   L
            ["1111111", "0010000", "0001000", "0010000", "1111111"], _  ;   M
            ["1111111", "0010000", "0001000", "0000100", "1111111"], _  ;   N
            ["0111110", "1000001", "1000001", "1000001", "0111110"], _  ;   O
            ["1111111", "1001000", "1001000", "1001000", "0110000"], _  ;   P
            ["0111110", "1000001", "1000001", "1000011", "0111111"], _  ;   Q
            ["1111111", "1001000", "1001100", "1001010", "0110001"], _  ;   R
            ["0110010", "1001001", "1001001", "1001001", "0100110"], _  ;   S
            ["1000000", "1000000", "1111111", "1000000", "1000000"], _  ;   T
            ["1111110", "0000001", "0000001", "0000001", "1111110"], _  ;   U
            ["1110000", "0001100", "0000011", "0001100", "1110000"], _  ;   V
            ["1111110", "0000001", "0000010", "0001100", "0000010", "0000001", "1111110"], _;   W
            ["1100011", "0010100", "0001000", "0010100", "1100011"], _  ;   X
            ["1100000", "0010000", "0001111", "0010000", "1100000"], _  ;   Y
            ["1000011", "1000101", "1001001", "1010001", "1100001"], _  ;   Z
            ["0000000", "0000000", "0000000", "0000000"], _             ;   [
            ["0000000", "0000000", "1111101", "0000000", "0000000"], _  ;   \
            ["0000001", "0000010", "0000000"], _                        ;   ]
            ["0000000", "0000000", "0000000", "0000000"], _             ;   SPACE ^
            ["0000000", "0000000", "0000000", "0000000"]] ;   SPACE _
EndFunc   ;==>Font

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

The simplest way might be to use an icon. Create nice images for the led as ON and OFF then set the image for the icon as and when needed using GUICtrlSetImage.

post-3602-0-37814300-1387050391_thumb.pn

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • Solution

You can try the GDI+ version made by Eukalyptus: http://www.autoit.de/index.php?page=Thread&postID=140164#post140164

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

That is fantastic marquee behavior.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

The simplest way might be to use an icon. Create nice images for the led as ON and OFF then set the image for the icon as and when needed using GUICtrlSetImage.

attachicon.gifledsIusingcons.png

martin, many thanks for the reply (and for the leds)

I had already tried to use the images of LEDs, but then I saw that "GUICtrlSetImage" does not allow you to place the image in a selected point and I should use a container that can be placed, and then put the image inside. The overall result that I have obtained is a slower graphical effect.

Also, using the images, I can not change at will the color of the LEDs.

My concern was instead about my use of "GUICtrlCreateLabel" to simulate the LEDs.

Although in this way I can place the "label" exactly where I want and I can also easily change the color of the LED by changing the background of the textbox, I'm afraid that this way of using too many "GUICtrlCreateLabel" is not a good way. ( I think it's a workaround rather than a good graphical solution).

Maybe what I need is a suggestion for a simple and lightweight way to easily draw "pixels" that can be positioned, sized and colored as required on a form (the optimum should be an also faster drawing effect then that obtained by the "GUICtrlCreateLabel").

For example, a simple and fast subroutine that I pass 5 parameters: XPosition, YPosition, Xlen, Ylen, RGB and get a square or rectangular pixels filled with RGB colour on the form. or another subroutine that I pass four parameters XCenter, Ycenter, radius and RGB and get on the form a circle filled with RGB colour (perhaps using GDI+ but I know nothing about the GDI+ stuff)

 

You can try the GDI+ version made by Eukalyptus: http://www.autoit.de/index.php?page=Thread&postID=140164#post140164

Br,

UEZ

wow, thanks UEZ for that link. that's amazing!

i have to study that stuff to see what I can get....

thanks again.

edit:

:o really wonderfull!! :thumbsup:

 

That is fantastic marquee behavior.

I agree with you if you are talking about UEZ's link of course (or are you referring to my draft? :idiot:)

Edited by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...