06-13-2018 04:20 AM
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 😄
Solved! Go to Solution.
06-13-2018 05:03 AM
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 ;/
06-13-2018 05:58 AM - edited 06-13-2018 06:01 AM
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
06-13-2018 06:09 AM - edited 06-13-2018 06:09 AM
06-13-2018 07:22 AM
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.
06-13-2018 07:32 AM
@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!
James
06-13-2018 07:40 AM
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
06-13-2018 12:36 PM
Thanks, I will try to use your proposition of solution 😉
06-13-2018 01:31 PM
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?
06-14-2018 02:16 AM - edited 06-14-2018 02:17 AM
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.