LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Ecsaping LED from the mouse

Solved!
Go to solution

I must : build a program containing two buttons, one button (STOP), manages the work of the program. Pressing it will end the program.
On the front of the panel, apart from the STOP button, there should be a flashing LED. Hovering the cursor the mouse on the LED area is to cause the LED diode to change position on the screen. The diode can change your location to any place in the front area of ​​the panel. Next moving the mouse cursor over the LED causes its dislocation.

I joined something what i tried to do.

I have a problem with the fact that the diode escaping into a random place, escapes from the visible area of ​​the panel.

Good people help me 😄

 

Download All
0 Kudos
Message 1 of 10
(2,608 Views)

I do not know how to make the LED escape in the range of an open window, and not outside it. and this is not about multiplying a random number by a constant, I need to use the window dimensions for this ... just how ;/

0 Kudos
Message 2 of 10
(2,587 Views)

I think you are trying to complicate things here...

If I understand things, it looks like you want to create a game: The user moves the mouse around the FP. and when the mouse is over an LED indicator, the indicator will move to a different place. This will continue until the user presses the stop button.

 

Basically It looks like you might be resizing the LED instead of moving it, but I can't tell as I can't open the VI.

 

However I would:

1) Initialise the VI by getting the FP bounds, determine the size of the FP and create a virtual grid (2D array of Origin points for the LED movement.

2) I would then move the LED to a position on the grid (grid size can be defined by LED size, FP size and how difficult you want to make the game.)

3) I would then wait for a mouse enter event to detect the Mouse going over the LED and reduce the loop speed. (I would then pick a random new row and column to move the LED to from the array of pre-generated Origin points and move the LED.)

4) The LED blinking I would be tempted to change to a round colour box and change the colours in a separate loop with it's own rate timer for more fluid fun.and colour options.

5) I would be tempted to ensure that the grid has a mask which ensures that the LED can never land on top of the stop button - that would be annoying.

6) I might change grid size and update speed (of LED move) to provide different levels of the game.

 

James

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 3 of 10
(2,571 Views)

Hi Beata,

 

so you know how to use property nodes!

All you need is a property of the front panel to read its current size…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 10
(2,568 Views)
Solution
Accepted by topic author BeataaGiee

The problem is that Panel Bound is in global screen coordinates, however LED's Position is in Panel coordinates (you may see their axes in the Front Panel while in development mode). So, you need to get the ContectRect property of the first Pane (this is a single Pane vi), which gives you the Pane rectangle in Panel coordinates.

Also, you only need to hook the Mouse Enter event of the LED, with no extra checks.

Finally, remark that with your original positioning (corrected), the LED corner may be moved so near to the right or bottom border of the Front Panel that you may not see it any more; hence you need to limit the movement some way.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 5 of 10
(2,551 Views)

@pincpanter wrote:

The problem is that Panel Bound is in global screen coordinates, however LED's Position is in Panel coordinates (you may see their axes in the Front Panel while in development mode). So, you need to get the ContectRect property of the first Pane (this is a single Pane vi), which gives you the Pane rectangle in Panel coordinates.

Also, you only need to hook the Mouse Enter event of the LED, with no extra checks.

Finally, remark that with your original positioning (corrected), the LED corner may be moved so near to the right or bottom border of the Front Panel that you may not see it any more; hence you need to limit the movement some way.


Hi Paulo,

The movement was being limited, just the wrong panel definition for the size definition being used.(and no account of the LED size or origin being taken into account when doing the limiting) - hence the method I suggested, the maths is done once, not every time and that makes it easier to debug.

Beata is nearly there, just depends on if an efficient program or one that works is the goal.

- Although with your experience I'm sure you could suggest another way to skin the cat/panther!Smiley Wink

 

James

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 6 of 10
(2,546 Views)

To be honest, I did not read carefully your post, as your first guess was wrong (she was not trying to resize the LED indicator).

However I agree with you that Beata is near to the solution, she only needs to become accustomed with the plethora of LabVIEW position/size  properties.

Meeeow

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 7 of 10
(2,542 Views)

Thanks, I will try to use your proposition of solution 😉

0 Kudos
Message 8 of 10
(2,516 Views)

And I have question, what is a difference between your proposition on the picture and the using just a function unbundle by name? It is about data type?

0 Kudos
Message 9 of 10
(2,506 Views)

I chose to let the LED leak half out of the visible Front Panel.

It's an arbitrary choice, you may drop the division by 2. In this case, the control will always be completely contained in the FP.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 10 of 10
(2,444 Views)