Help I need some body.

Mark.R

Member
Hi all,

Sorry to quote a bettles line. My question is, is there anyone on the forum that live anywhere near Newtown in mid Wales who knows abit about the programing side of the picaxe chips and wouldn't mind having a chat face to face.

Mark
 

hippy

Technical Support
Staff member
Not me, but if you ask here you may well get the answers you need, or at least get someway to where you need to be to make any personal encounter more productive and useful - Having an idea about what you're needing to know may even help get someone interested and encourage them to step forward !
 

Mark.R

Member
Its all aspects of writing a program like the alarm that I posted last week. I have the big picaxe book and have read it but I just get lost, maybe I'm just a 25yr old old school hardware type person.
 

Rickharris

Senior Member
Its all aspects of writing a program like the alarm that I posted last week. I have the big picaxe book and have read it but I just get lost, maybe I'm just a 25yr old old school hardware type person.
Start simple;

6 commands:

High
Low
Wait/pause
Goto
If ... Than
For...Next


Understand how labels work

Start with flashing LEDs in various combinations - I have in the past posted some school tasks that get students started. Here http://www.picaxeforum.co.uk/showthread.php?t=8893

Most of what you want to do can be done with these 6 commands - you will learn others like sound, PWM, Pulsein as and hen you need them and gain confidence.

Write out in English what you need your programme to so - make this a list on the correct order of events. this then guides you in building your programme.

Experiment. Ask questions here. Ponder long and deep (Personally I recommend a good pint or red wine to help pondering but your choice - Most of my best ideas have been filtered through alcohol - So much so that i often can't remember the very best ideas so well filtered are they!)
 

Mark.R

Member
One question I do have is how do you have to things going on at the same time, for example the alarm post again, how would I have the 10 or so second exit timer running and the LED flasing fast and then going to a slow flash at the end of the exit time with the alarm going into the armed mode say.
 

BeanieBots

Moderator
With a PICAXE, you can only do one thing at a time. However, with just a little thought, it is possible to make it appear as if more than one thing is going on at the same time.
For example, if you wanted an output to go from low to high after 10 seconds and have an LED flashing, then you simply flash the LED a set number of times for a known period to make up the total time of 10 seconds.
eg.
Low 0 'output 0 starts off low.
For b0 = 0 to 40 'a loop that will execute 40 times
high 1 'turn on the LED
pause 125 'wait with LED on for a short period
low 1 'turn off the LED
pause 125 'wait with LED off for a short period
next b0 'go back to the start of the loop until all 40 are done
High 0 'set the output high

by altering the pause times you can alter the total time taken between output 0 going from low to high. By altering the "40" in the for/next line, you can alter how many times the LED goes on and off between output 0 going from low to high.

If you break your problem down into simple sections (as has already been suggested) each part becomes an easier problem to solve.
Just 'walk' through the problem and draw it out. Converting that into code is then just a case of reading up about the commands.

You don't need much other than high/low, if/then.
I've thrown in For/next because it is a simple way making a loop do something a set number of times but you just as easily create your own loop using a variable to count how many times you've been through the loop and exit (look at goto) when the desired number is reached (if/then).
 
Last edited:

womai

Senior Member
On the 28X1 or 40X1 parts (where you have a timer interrupt available), you can also get more sophisticated: the timer calls an interrupt routine in regular intervals, there you can e.g. toggle the LED. The main program can do something else (and gets interrupted by the timer interrupt). You can even use some sort of "time slicing"/"round robin" multitasking where each time the interrupt routine gets called you work on a different task. If it gets called often enough per second, then the user's impression is as if several things were going on at the same time.

For a short code example, see here:

http://www.picaxeforum.co.uk/showthread.php?t=8541

Wolfgang
 

hippy

Technical Support
Staff member
Not to criticise the above suggestions but I guess you're feeling way out of your depth at the moment, so while that 'all sounds great', you're probably getting no closer to having a clue about doing it.

What I'd suggest is to start simple as suggested earlier. Just getting a LED flashing in a loop. Then work out how to move to a different loop where the LED flashes at a different rate and back again when a button is pushed.

Once you've done a bit of coding like this it will hopefully become clearer and snap into place. You'll also beging to see that your own code and other people's looking similar and what people suggest will start to make more sense.
 

gidgee

Member
Take heart MARK R

Take heart MARK R, you are in good hands and you will learn, 30 odd years ago I did not Know what hi or low case meant on a key board, I purchased a Commodore 64 and taught my self the them spurned BASIC , can now prog. up to VB5, have lost interest in VB due to MS greed, but that is another story, and take note what the HIPPY says, I have pages and pages of his thoughts on programming etc.
Head down and bum up and it will come to you
john
 

Mark.R

Member
Thanks to all that have geed me along to lean. On the subject of the alarm post from last week and three hours later I have writen the program attached and it seems to work how I want it to (in the end).

Could one of you have a look over it and see what you think for someone who dosn't realy know what he is doing and see if you can spot any problems with it. I have labed each line as much as I could so I know what its doing.

Mark
 

Attachments

eclectic

Moderator
Mark.
A few thoughts.

1. The "pause 0" lines. Change to say pause 250

2. "Disarming:" ; How do you get there?

3. Have you run this program in the simulator?

4. Have you got 18X / board / Piezo / LED's so that you can model the circuit?

e.
 

kevrus

New Member
On first glance, should this line:

Code:
if pin0 = 0 then goto disarmed	'arm key off, disarm system
which appears in the 'armed', 'ALARM', and 'entry' sub-routines, read as

Code:
if pin0 = 0 then goto disarming	'arm key off, disarm system
which would then allow the program to get to "disarming" as eclectic points out?

You should give yourself a pat on the back, I think you have done very well indeed!
 
Last edited:

Mark.R

Member
Thanks Kevrus for the prase, Iv supprised myself.

I have changed the line that you both pointed out and it works whichever may its writen.

The reason for the pauses being zero is that I wonteded the led output to flash fast on the simulator, but will have to be altered when its writen to the chip.

I have most of the parts on the way, just got to find the time.

Mark
 
Top