Skip to main content

Use Visual Basic to enhance the Display

 The reason that I like VB as a Programming Environment is the ease with which you can make it look nicer or Enhance the Display if you want to sound fancier about it.

If we take the Red LED - Green LED Program, we can another couple of features which show the beginnings of what might appear in a mimic panel.  So the first thing we would do is to add a couple of Shapes (another type of VB Object).

We put a shape beside the Red Control buttons then set the properties to :-
Shape = circle
Fillcolor = Red
Bordercolor = red
Name = Red_Circle

Do the same for the second, green, shape.

Then we edit the VB code

Private Sub Red_Off_Click()
  MSComm1.Output = "r"                   '   Sends r Switch off Red
  Red_Circle.FillColor = vbWhite       '   Changes the fillcolor to white
End Sub

Private Sub Red_On_Click()
  MSComm1.Output = "R"        '   Sends R Switch on Red
  Red_Circle.FillColor = vbRed
End Sub

Running the Program now gives an improved display.



The important thing now, is that we don't need to do anything to the Arduino Code. Any changes now can all happen in the VB Environment.

You can do all kind of things such as hiding an "On" button after it's been pressed, so that you can't press it again by mistake.  Then "Show" the On Button after you press the "Off" button.

Another idea is to set a single button as a "Toggle" button.
For the Red LED, the logic is to 
    look at the Fillcolor
        If the fillcolor is red                  (ie it is on)
           set the fillcolor to white         (switch it off)
        else                                            ( what you do if the fillcolor is NOT red )
            set the fillcolor to red            (ie switch it off)
        end if                                         ( this ends any code caused by the earlier If condition )

What will this look like in VB Code?

Private Sub Red_Toggle_Click()

  If Red_Circle.FillColor = vbRed Then    '  Red LED is already on
     MSComm1.Output = "r"                       '  Sends r Switch off Red
     Red_Circle.FillColor = vbWhite           '  changes the light to white / off
  Else                                                           '  what to do if red LED is NOT on
     MSComm1.Output = "R"                      '  Sends R Switch on Red
     Red_Circle.FillColor = vbRed              '  changes the light to Red / on
  End If                                                       '  finishes of the "If" condition
  
End Sub

And that, dear reader, is why I like Visual Basic.

Comments

  1. This is a lot easier to build in VB. It has taken me a full day to create two buttons to switch on and off an led and I have still to make the button change colour to show the status on the screen.

    ReplyDelete

Post a Comment

Popular posts from this blog

Train sequence / timetable using Arduino

                              Following discussions in a MERG Zoom meeting about potential projects for the Cumbria virtual area group I have started this blog to share my ideas for building a train sequence / timetable system based on an Arduino UNO. The trigger for this project was Andy Robb's article in the MERG journal (June 2020 edition). In it Andy describes using an UNO with a OLED display to produce an electronic station display board.  Having tried out Andy's version I started thinking about expanding the idea and have come up the following list of possibilities: 1. Replace my card index train sequence with an electronic version. 2. Have the train sequence synchronised with the on platform displays. 3. Display an analogue clock on the station display and have it display the train times. 4. Store the position reached in the sequence so that it starts where it left off on power up.  To mak...

Safety in the workshop

 An excellent presentation by Dr. Craig Lennox on workshop safety at today's West of Scotland area group meeting. An amusing but nevertheless serious video was followed by a detailed talk on safety and first aid. I am hoping this talk will be made available on the WOSAG website in due course. The take home message is to ensure your workspace is well ventilated, tidy with no trailing cables. Plan what you are going to do using appropriate tools, avoid distractions and don't rush A clear head is essential. Use PPE where necessary for example ear protection, safety glasses and laser glasses. The risks of burns, cuts, electrical shock and inhalation of dust and fumes were all covered in some detail. Automatic External Defibrillator (AED) are now installed in most supermarkets. A short video was shown illustrating just how easy they are to be used. Excellent talk.  Keep safe everyone.

Mimic Points in Visual Basic

For this project, I wanted to create a moving graphic to mimic a set of points moving from one position to the other.  This Blog shows all that is needed. The first Picture shows the 6 lines needed.                                 This Picture shows the Line Properties.    The tracks are shown with 5 lines, though only the middle ones in red are involved.  The other line shown below the others is the one that actually "moves".  It is shown below the other lines for clarity only.  At the start of the Program running, it is positioned over the lower red line. In VB, each Line has properties and these are shown above.  To get a line to appear to move, all that needs to be done is to gradually change the X2 and Y2 co-ordinates of the line. This is the code for the program. The first 6 lines create a pause Function in the program, by using the Computers internal C...