![]() |
Forum Index : Microcontroller and PC projects : Not quite sure??
Author | Message | ||||
mikedownunder![]() Newbie ![]() Joined: 03/03/2016 Location: AustraliaPosts: 26 |
Hi All I am new to the Back Shed forum, although not with BASIC. Please allow me to tell you a general background about myself. ![]() My name is Mike and I am now retired after working originally as an electrician and then for the most part as an Electronics technician. My Basic 'training' started on a Commodore 64, which I am sure some of the older generation will remember. I then progressed to what was called in the UK a 'BBC' computer made by Acorn which was extremely popular. I was working at IBM in the UK at the time and there were over 200 'BEEB' users on site, so we had a lot of fun. In 2002 I picked up on the now very popular and well supported Proton Basic Development Suite (PDS). I have noticed the various different 'package' processors in the past few years (Arduino) etc., but I do like the look of the Micromite, Mainly I suppose because it uses a PIC which, of course, I am very familiar with plus I have the Pickit3 for programming when required. Anyway I have been looking at the 'Parking Assist' program written by Geoff. Most of the commands are easily translated from one compiler to the next, however I have some questions about things that I cannot find an explanation for after looking in the MMBasic manual. 1. In the program listing what does 'DrawOption' mean and where does it come from? 2. Under 'Get selected button and take action on the button'. In the Select Case I assume that in Case2 'GetThresholds' means got to the Sub GetThresholds? 3. What is the difference between Sub, End Sub and Gosub, Return? I want mainly to use only the part of the program which has a keypad. But I do like to understand things even if I am not using it at the time. Thanks for being patient reading this long post and any help will be gratefully received. ![]() Mike |
||||
Justplayin![]() Guru ![]() Joined: 31/01/2014 Location: United StatesPosts: 327 |
Hi Mike and welcome to the forum! I can't seem to find the 'Parking Assist' program you are referring to at the moment, but I believe you have correctly figured out that 'DrawOption' and 'GetThresholds' are both SUBS. SUB are very much like using GOSUB but with some advantages. They allow you to create your own commands. You may pass them arguments if you wish and they have access to all the other variables of your programs. However, you can also localize the variables within the SUB to prevent conflicts with existing variables in your program. The 'END SUB' quits the SUB and deletes all the localized variables then returns control back to where the SUB was called from. 'Fifth power of number, a totally pointless program For i = 1 To 10 Fifth(i) Next i Print x, y End Sub Fifth(x) Local i,y y=1 For i = 1 To 5 y = y*x Next i Print y End Sub If you run this program in the program it will print out the following, and notice X and y are 0. x and y only exist when the SUB is being executed. Also, notice I used the variable i in the main program and the SUB at the same time and it does not cause a problem because i in the SUB is Local to the SUB only. 1 32 243 1024 3125 7776 16807 32768 59049 100000 0 0 Does that help... or did I confuse you more? --Curtis I am not a Mad Scientist... It makes me happy inventing new ways to take over the world!! |
||||
paceman Guru ![]() Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
@mikedownunder Hello Mike, welcome to the forum. @Just playin Hi Curtis - the Parking Assist program is part of a project Geoff described in the current March issue of Silicon Chip (SC) magazine. The program is available from SC but I've just had a look at Geoff's site and I can't see it there so I guess he hasn't generally released it yet. If you PM Geoff I think he'd be happy to send you a link. Greg |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2934 |
@Justplayin A very good example - and very well explained ![]() |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6270 |
The code is available from silicon chip magazine. http://www.siliconchip.com.au/Shop/6/3342 Jim VK7JH MMedit |
||||
mikedownunder![]() Newbie ![]() Joined: 03/03/2016 Location: AustraliaPosts: 26 |
Hi All This is the file from SC. 2016-03-09_052333_2016-01-23_080736_ParkingAssist.zip Thanks for the info on Sub's it certainly covered the detail. However my other question remains unanswered, namely. 1. In the program listing what does 'DrawOption' mean and where does it come from? In the attached program this is listed on lines 127 - 129, under Sub GetOptions. There is no variable or array declared for DrawOption, so how come I don't get a syntax error? I can see what the action does, but as I said I like to know the whole story and why things are done a certain way. Thanks again for any help. Mike |
||||
disco4now![]() Guru ![]() Joined: 18/12/2014 Location: AustraliaPosts: 1000 |
I think you will find the SUB DrawOption in the code there somewhere. It looks like this. Regards Gerry ' draw a single option Sub DrawOption n As Integer, colour As Integer, caption As String, vert As Integer, var As Float, units As String Const btn_width = 80'120 Const fonth = MM.FontHeight * 2 Const space = 4 Text MM.HRes/2, vert, caption, CT, 2, 1, colour If var <> -1 Then Text MM.HRes/2 - 20, vert + fonth + space, Str$(var) + " " + units, RT, 2, 1, colour key_coord(n,0) = 220'MM.HRes/2 + 20 'x key_coord(n,1) = vert + fonth + space/2 key_coord(n,2) = btn_width key_coord(n,3) = fonth + space key_coord(n,4) = RGB(cyan) key_caption(n) = "SET" DrawButton n, 0 End Sub Latest F4 Latest H7 FotS |
||||
mikedownunder![]() Newbie ![]() Joined: 03/03/2016 Location: AustraliaPosts: 26 |
Oh my, I feel such an idiot ![]() Thanks Gerry. I guess it's where I am used to using Gosub's and not recognising the SUB's. Hopefully I can start to understand what's going on a bit better now. ![]() So thanks again everybody for the help. I'll probably be back with other questions soon. Mike |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |