Home  |  Contents 
Microcontroller and PC projects
  Forum Index : Microcontroller and PC projects         Section
Subject Topic: Newie got a few questions Post ReplyPost New Topic
<< Prev Page of 33 Next >>
Author
Message << Prev Topic | Next Topic >>
paceman
Guru
Guru


Joined: 07 October 2011
Location: Australia
Online Status: Offline
Posts: 1161
Posted: 06 March 2016 at 11:43am | IP Logged Quote paceman

@WW and @lew247

Underscore is OK - Page 48 of MMBasic V5.1 Manual, MMBasic Characteristics, Naming Conventions.

Variable names and labels can start with an alphabetic character or underscore and can contain any alphabetic
or numeric character, the period (.) and the underscore (_). They may be up to 32 characters long. A variable
name or a label must not be the same as a command or a function or one of the following keywords: THEN,
ELSE, TO, STEP, FOR, WHILE, UNTIL, MOD, NOT, AND, OR, XOR, AS. Eg, step = 5 is illegal.


Greg

EDIT: You gotta be quick to beat Peter to the draw

Edited by paceman on 06 March 2016 at 11:45am



Back to Top View paceman's Profile Search for other posts by paceman
 
WhiteWizzard
Guru
Guru


Joined: 05 April 2013
Location: United Kingdom
Online Status: Offline
Posts: 2436
Posted: 06 March 2016 at 11:48am | IP Logged Quote WhiteWizzard

Peter, Greg - Thanks for confirming you can use!

Although its still worth mentioning on Page 33 in Manual to refer to Page 48 for naming conventions IMHO.

That OPTION EXPLICIT gets me all the time

__________________
For everything MicroMite visit MicroMite.org

Direct Email: WhiteWizzard@MicroMite.org
Back to Top View WhiteWizzard's Profile Search for other posts by WhiteWizzard Visit WhiteWizzard's Homepage
 
paceman
Guru
Guru


Joined: 07 October 2011
Location: Australia
Online Status: Offline
Posts: 1161
Posted: 06 March 2016 at 11:50am | IP Logged Quote paceman

WhiteWizzard wrote:
Although its still worth mentioning on Page 33 in Manual to refer to Page 48 for naming conventions IMHO

Yes, I'd agree with that.
Back to Top View paceman's Profile Search for other posts by paceman
 
lew247
Guru
Guru
Avatar

Joined: 23 December 2015
Location: United Kingdom
Online Status: Offline
Posts: 790
Posted: 06 March 2016 at 1:17pm | IP Logged Quote lew247

Weird - If I rem out or delete Option Explicit the program runs

I have errors in the program as it's giving the wrong information and other things,
BUT it runs
no idea why!
Back to Top View lew247's Profile Search for other posts by lew247
 
matherp
Guru
Guru


Joined: 11 December 2012
Location: United Kingdom
Online Status: Offline
Posts: 1851
Posted: 06 March 2016 at 3:41pm | IP Logged Quote matherp

Quote:
Weird - If I rem out or delete Option Explicit the program runs


This isn't weird, if you don't have OPTION EXPLICIT then the Micromite will create automatically a variable the first time it is used. This is why it is so important to use it in big programs. For example without OPTION EXPLICIT

myvariable = 1
...
...
...other code
...
newvariable=myvariabl*4

newvariable will be equal to 0.

Basic has automatically created the variable "myvariabl" which was actually a typo.

with OPTION EXPLICIT

DIM INTEGER myvariable = 1
...
...
...other code
...
newvariable=myvariabl*4

gives the "variable not declared error" so you can easily see your problem.

You will also see in my code I also use "OPTION DEFAULT NONE"

This means that I have to declare each variable as a string, integer, or float. Again this seems like adding work, but by doing it you know that the variable will always have the correct type for the use you want.
Back to Top View matherp's Profile Search for other posts by matherp
 
lew247
Guru
Guru
Avatar

Joined: 23 December 2015
Location: United Kingdom
Online Status: Offline
Posts: 790
Posted: 06 March 2016 at 4:34pm | IP Logged Quote lew247

Thanks matherp,that explains it nice and easily
Back to Top View lew247's Profile Search for other posts by lew247
 
lew247
Guru
Guru
Avatar

Joined: 23 December 2015
Location: United Kingdom
Online Status: Offline
Posts: 790
Posted: 11 March 2016 at 10:37pm | IP Logged Quote lew247

Back again - (sorry)

How do I say this?

IF hour = 02 and if min = 05 then 'sync clock code goes here
end if
Back to Top View lew247's Profile Search for other posts by lew247
 
TassyJim
Guru
Guru


Joined: 07 August 2011
Location: Australia
Online Status: Online
Posts: 2277
Posted: 12 March 2016 at 12:01am | IP Logged Quote TassyJim

IF hour = 02 and min = 05 then 
'sync clock code goes here
end if


You will also need some way to make sure that you only sync once per hour.
Otherwise you may end up setting the time hundreds of times during the one minute window.

How you do that will depend on the rest of your program flow.
One way is:
IF hour = 02 and min = 05 then 
    if lastsync <> hour then
        'sync clock code goes here
        lastsync = hour
    end if
end if


It will only run the sync part once for each hour no matter how many times the routine is called.
lastsync needs to be a global variable if you are using a SUB or FUNCTION

Jim

__________________
It all started with the ZX81....
VK7JH
http://www.c-com.com.au/MMedit.htm
Back to Top View TassyJim's Profile Search for other posts by TassyJim Visit TassyJim's Homepage
 
lew247
Guru
Guru
Avatar

Joined: 23 December 2015
Location: United Kingdom
Online Status: Offline
Posts: 790
Posted: 12 March 2016 at 9:35am | IP Logged Quote lew247

Thanks TassyJim
I didn't realise that you could actually use IF AND THEN statements
Back to Top View lew247's Profile Search for other posts by lew247
 
WhiteWizzard
Guru
Guru


Joined: 05 April 2013
Location: United Kingdom
Online Status: Offline
Posts: 2436
Posted: 12 March 2016 at 9:48am | IP Logged Quote WhiteWizzard

A useful bit of advice about IF....AND...OR..... THEN ... Try and get in the habit of using brackets to separate the test conditions to eliminate potentially difficult to find bugs.

So it is 'useful' to do something like:

IF (....) AND ( (....) OR (...) ) THEN

NOTE: the brackets are not necessary in terms of logic providing you keep on top of things. However, I have been helping a few people recently where the lack of brackets was resulting in errors in the 'output'.

WW

__________________
For everything MicroMite visit MicroMite.org

Direct Email: WhiteWizzard@MicroMite.org
Back to Top View WhiteWizzard's Profile Search for other posts by WhiteWizzard Visit WhiteWizzard's Homepage
 
paceman
Guru
Guru


Joined: 07 October 2011
Location: Australia
Online Status: Offline
Posts: 1161
Posted: 12 March 2016 at 1:07pm | IP Logged Quote paceman

TassyJim wrote:
You will also need some way to make sure that you only sync once per hour. Otherwise you may end up setting the time hundreds of times during the one minute window.
How you do that will depend on the rest of your program flow.
One way is:.....

Another option to Jim's method is to use the SETTICK command. The following will interrupt the main program hourly to do the syncing.

Greg

SETTICK 3600000,Syncsub
SUB Syncsub
.
.
END SUB

Back to Top View paceman's Profile Search for other posts by paceman
 
lew247
Guru
Guru
Avatar

Joined: 23 December 2015
Location: United Kingdom
Online Status: Offline
Posts: 790
Posted: 12 March 2016 at 1:21pm | IP Logged Quote lew247

I like the settick option, but I only want it to send the time once a day at 2:05AM
Saves me writing code on the indoor unit to change the time when DST/BST comes and goes when the outdoor unit with the gps already does that.

I might get it to only send the time on power up and then on the DST/BST change dates, not sure yet I'll decide later on when I start thinking about the indoor unit.
Back to Top View lew247's Profile Search for other posts by lew247
 


<< Prev Page of 33 Next >>
In the news...
 
Post ReplyPost New Topic
Printable version Printable version
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

Powered by Web Wiz Forums version 7.8
Copyright ©2001-2004 Web Wiz Guide

This page was generated in 0.1563 seconds.
Privacy Policy     Process times : 0, 0, 0, 0.16