Skip to main content

Posts

Visual Basic Code in a Mimic Panel

Visual Basic is what is known as on Object Oriented Language, so you add Objects (Lines, Boxes, Shapes) to a form and then create some matching code which is executed when you Click (usually) on that object.  The modified Form for the Points Program now looks like. The objects on this form are Lines 1 and 2, Shapes 6 and 7 and a couple of Command Buttons called Clockwise and Anti Clockwise.  When we Click on Clockwise, then some code is executed. This lot !! Private Sub Clockwise_Click()     MSComm1.Output = "C"                  ' Sends a "C" to the Arduino code which makes the Servo turn     Clockwise.Enabled = False                   ' Disables the "Clockwise" button so we can't press it by mistake     Line2.BorderColor = &HC0C0FF    ' Changes Line 2 to a beige kind of colour     Line1.BorderColor = &HC0C0FF  ...

Visual Basic, Arduino and Points

 Step 3 in this process was to get the Servo to rotate more slowly than before. This is the modified Arduino Code // the next block of code sets up a loop in the Program to rotate the Servo 1 step at a time. //  This way, we get a 'smooth' movement, rather than a sudden one if (Inpchar=='A') {                          // checks Input character A for Anticlockwise     delay(300);                                 // a wee pause (for dramatic effect!! )     for (int i = 0; i <= 135; i++) {     //  a variable i goes 1, 2, 3, 4 . . up to 135           servoPos = i;                              //  send the new value to the Servo controller           delay(30);  ...

Visual Basic, Arduino and a Servo

The overall plan is to end up with a Model Railway Layout which is being controlled from a Laptop computer by clicking (or pressing) buttons on some form of mimic panel displayed on the Laptop.   The LEDs are working, so now on to getting a Servo to behave.   Many thanks first of all to Paul McWhorter on Youtube for his series of video instructions https://www.youtube.com/playlist?list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP Tutorials no. 30 and 31 are the ones about Servos, how to connect them and control them.   The Visual Basic Code and Form In VB, make up a form with 4 Buttons.   For this simple version, we only need 2 of them.  We will ignore the "pretty coloured" ones just now!! CW for Clockwise              ACW for Anti Clockwise This is all the code needed for these buttons. Private Sub Basic_AC_Click()      ' This is the code which is executed when the ACW button is us...

Document First - then Code

 Davy Dick's talk to the JAL Special Interest Group last night was a not to be missed event for anyone wishing to program in any language. The critical analysis process was succinctly expressed as " If you can't describe it - you can't code it" Comments in a program are essential for the understanding of others and for yourself if looking at it after a prolonged delay. Davy suggests that we shouldn't write code and then comment on it, but the opposite. Write comments describing your requirements and then write the code for each part. Davy used a few examples to outline his method of designing using Psuedo Code. A road roller, a canal boat with intermediate animations, a traffic light simulator, a lighthouse and Ezypoints were demonstrated and discussed showing different programming methods. I would recommend that you watch this presentation which is now available on the JALSIG area of the MERG website. You might have to Join the JAL Special Interest Group to...

East of Scotland Demo layout

At today's West of Scotland Area Group meeting, we were treated to a presentation and demonstration by Chris Cosgrove from the East of Scotland Area Group. Their layout is a basic oval with two additional loop sidings. A further siding leads to a turntable off which is a track to an engine shed. To add interest, a working level crossing with flashing lights will be added. The layout is controlled using an EzyBus controller, one input board and two output boards all connected by I2C.  The level crossing is triggered by two laser TOTI's (one each side). To create the necessary delays, Chris designed a circuit using the PIC 12F675, the outputs of which are fed to the EzyBus Input Board. Switches are also connected to the Input Board for point selection, Engine shed door operation and turntable position selection. The Output boards are used for Servo Control of the points, the automation of the Engine Shed doors and for the level crossing gates. Additional digital outputs control t...

Visual Basic & Arduino

The project I'm working on just now involves writing a Program in Visual Basic 6.0 (a Programming Environment I'm comfortable in) linked to an Arduino Uno. So far, I've got as far as controlling a set of traffic lights (3 LEDs on a bit of Breadboard) but I'm happy with that progress so far.  There's a long way to go on this, a steep learning curve, but courtesy of Covid 19, I have a lot more time to devote to this kind of project than I would usually have at this time of year. So far, I have one way communication, next challenge is to get information going the other way.  Web forums are very useful things. For those of you who want to see the "nuts & bolts", here is the Arduino Code int redled= 12; int amberled=10; int greenled=8; char Inpchar; void setup()  { pinMode(redled,OUTPUT); pinMode(amberled,OUTPUT); pinMode(greenled,OUTPUT); Serial.begin(9600); }  void loop() { if (Serial.available())  { Inpchar = Serial.read();}  // Reads single character fr...

Interested in Programming Technique?

The JAL Special Interest Group has a meeting on Monday 14th September at 19:30     These are sessions that are open to all members, both in the UK and internationally. It normally discusses programming PIC chips using the JAL programming language.  Davy Dick from the West of Scotland Area Group will be the guest speaker and will be discussing how he goes about starting a program from scratch, using his automated canal barge and the traffic lights Pocket Money Project as examples.  As this session covers programming technique, it is also useful for Arduino and other platform  programmers.  If you have not yet signed up to JALSIG then you will have to   update your profile