Std Picaxe project board with Picaxe 18X

dropdad

Member
Is it possible to have two separate programs controlled by two different digital inputs on a Picaxe std project board running a Picaxe 18x micro? Both programs would operate the same outputs (LED lamps, utilizing the boards darlington driver) but both programs would never be expected to be used at the same time? Presently, to accomplish this, Im running two boards. I would like to get away from the two board arrangement. Maybe there is a better (larger capability) board you could suggest?
 

SAborn

Senior Member
Why cant you do it all in 1 picaxe and have the two programs in 2 sub routines, and depending on what input is switched call the sub routine for the required program.
 

westaust55

Moderator
You really do need to provide some additional information.

Why are you currently using two separate 18X chips now? (why is it so?)
What is the size of the programs?
Would they both fit into one chip as subroutines as SABorn sugegsts?

Can you post the programs.

Not looked into it greatly myself but X2 parts have program slots with a separate program in each slot and you might change from one slot to another which could be under switch control.

but really needs more information from you to enable folks to give the best answer
 
Last edited:

dropdad

Member
Running two programs on a Picaxe 18X (std project board)

Possibly I could run two programs with a routing written for each. On Page 6 of the Picaxe spec sheet for the standard project board, about half way down says additional inputs can be made by installing the proper resistor to change the analog input to a digital one. Is this where I would add the second input and then write the program for it but having the second program start when that input is selected? I'm pretty green when it comes to this stuff. I have had help in the past from the Picaxe Forum which was greatly appreciated!
There is only 40-50 lines of code for each program
 
Last edited:

westaust55

Moderator
I suggest that you provide a more detailed explanation of exactly what you are trying to achieve. Describing when each “routine” is to operate, what the routine does, purpose, any math, delays, etc, and what inputs and outputs are required (some many be common) to each “routines”.

Ideally, you should have this written out in words or as a flow diagram as a guide to developing your program regardless of needing help.

A decision/guidance on whether a single 18X or 18M2 can perform the task can then be made and the outline of the programming developed to suit from which you can then work on your project.
 

dropdad

Member
Two programs on one Picaxe 18X

Here are my two programs one after another. Both programs work when just one is programmed into my board. I want to be able to run both programs on one board with two different digital inputs. I installed a 10K resistor on my board so position 1 can now be used as a digital input along with position 2 (one for each program) Two things; I suppose but am not sure... one program has a line that says
"if pin2 = 1 then goto blink" Will the other program say if "pin1 = 1 then goto blink" ? (without the quotation marks, of course) and Question two, when I tried to put that into the MacAXEpad i got a syntax failure because of the main: being a duplicate. How do I write my program(s) so that the two can be started with the two separate inputs. Thank you.

main:


do
if pin2 = 1 then goto blink
loop

blink:



pause 500 ;no lights
let pins = %00010000 ;top light on
pause 500
let pins = %00000000 ;no lights
pause 500
let pins = %00001000 ;second amber light on
pause 500
let pins = %00000000 ;no lights
pause 200
let pins = %00001000 ;second amber light on
pause 500
let pins = %00000000 ;no lights
pause 200
let pins = %00001000 ;second amber light on
pause 500
let pins = %00000000 ;no lights
pause 200
let pins = %00000010 ;green light on 1/4 sec
pause 250
let pins = %00000100 ;third amber on 1/4 sec
pause 250
let pins = %00001000 ;second amber on 1/4 sec
pause 250
let pins = %00010000 ;top amber on 1/4 sec
pause 250
let pins = %00000000 ;no lights 1 1/2 sec
pause 1500
let pins = %00010000 ;turns on top amber lamp for 1.2 seconds
pause 1200
let pins = %00001000 ;turns on second amber lamp from top for 1.2 seconds
pause 1200
let pins = %00000100 ;turns on third amber lamp from top for 1.2 seconds
pause 1200
let pins = %00000010 ;turns on Green light for 4 seconds
pause 4000
let pins = %00000000 ;no light
goto main

main:

do
if pin2 = 1 then goto blink
loop

blink:



pause 500 ;no lights
let pins = %00010000 ;top light on
pause 500
let pins = %00000000 ;no lights
pause 500
let pins = %00011100 ;all amber lights on
pause 500
let pins = %00000000 ;no lights
pause 200
let pins = %00011100 ;all amber lights on
pause 500
let pins = %00000000 ;no lights
pause 200
let pins = %00011100 ;all amber lights on
pause 500
let pins = %00000000 ;no lights
pause 200
let pins = %00000010 ;green light on 1/4 sec
pause 250
let pins = %00000100 ;third amber on 1/4 sec
pause 250
let pins = %00001000 ;second amber on 1/4 sec
pause 250
let pins = %00010000 ;top amber on 1/4 sec
pause 250
let pins = %00000000 ;no lights 1 1/2 sec
pause 1500
let pins = %00010000 ;turns on top amber lamp for 1 second
pause 1000
let pins = %00001000 ;turns on second amber lamp from top for 1 second
pause 1000
let pins = %00000100 ;turns on third amber lamp from top for 1 second
pause 1000
let pins = %00000010 ;turns on Green light for 4 seconds
pause 4000
let pins = %00000000 ;no light
goto main
 

westaust55

Moderator
try this

Code:
MAIN: 


DO
  IF pin2 = 1 THEN               ; test the first pin
    GOSUB blink1 
  ELSEIF pin1 = 1 THEN        ; test the second input pin
    GOSUB blink2
  ENDIF
LOOP

blink1: 

pause 500 ;no lights
let pins = %00010000 ;top light on 
pause 500
let pins = %00000000 ;no lights
pause 500
let pins = %00001000 ;second amber light on
pause 500
let pins = %00000000 ;no lights
pause 200
let pins = %00001000 ;second amber light on 
pause 500
let pins = %00000000 ;no lights
pause 200
let pins = %00001000 ;second amber light on 
pause 500
let pins = %00000000 ;no lights
pause 200
let pins = %00000010 ;green light on 1/4 sec
pause 250
let pins = %00000100 ;third amber on 1/4 sec
pause 250 
let pins = %00001000 ;second amber on 1/4 sec
pause 250
let pins = %00010000 ;top amber on 1/4 sec
pause 250
let pins = %00000000 ;no lights 1 1/2 sec
pause 1500
let pins = %00010000 ;turns on top amber lamp for 1.2 seconds
pause 1200
let pins = %00001000 ;turns on second amber lamp from top for 1.2 seconds
pause 1200
let pins = %00000100 ;turns on third amber lamp from top for 1.2 seconds
pause 1200
let pins = %00000010 ;turns on Green light for 4 seconds
pause 4000
let pins = %00000000 ;no light
RETURN



blink2: 

pause 500 ;no lights
let pins = %00010000 ;top light on 
pause 500
let pins = %00000000 ;no lights
pause 500
let pins = %00011100 ;all amber lights on
pause 500
let pins = %00000000 ;no lights
pause 200
let pins = %00011100 ;all amber lights on
pause 500
let pins = %00000000 ;no lights
pause 200
let pins = %00011100 ;all amber lights on
pause 500
let pins = %00000000 ;no lights
pause 200
let pins = %00000010 ;green light on 1/4 sec
pause 250
let pins = %00000100 ;third amber on 1/4 sec
pause 250 
let pins = %00001000 ;second amber on 1/4 sec
pause 250
let pins = %00010000 ;top amber on 1/4 sec
pause 250
let pins = %00000000 ;no lights 1 1/2 sec
pause 1500
let pins = %00010000 ;turns on top amber lamp for 1 second
pause 1000
let pins = %00001000 ;turns on second amber lamp from top for 1 second
pause 1000
let pins = %00000100 ;turns on third amber lamp from top for 1 second
pause 1000
let pins = %00000010 ;turns on Green light for 4 seconds
pause 4000
let pins = %00000000 ;no light
RETURN
There are ways to make the code more compact if you wish to gain more space.
 

dropdad

Member
Dear westaust55,
Thank you so much...The program works perfectly!
And thanks to all responders on the Picaxe Forum. I knew I could count on you're help in resolving my problem. I only hope that someday, I'll be smart enough to help someone writing in to the forum, myself.
Thanks again!
dropdad
 

dropdad

Member
programming change

Dear westaust55
I have decided on two programming changes to the way my light array works but am lost in their implementation. I'm not sure how to go about writing the program for it. The above program suggestion you sent works perfectly but I wanted to add to it the following functions.
When the Picaxe circuit board it powered up, I want the output for (let pins = %00010000) to light for 1 second and go out and wait for either input 1 or 2 to operate the light sequence as the program is currently written. The light coming on for one second is to acknowledge the system's power switch has been turned on. Now the system is just waiting for one of the two input switches to be closed. The second change is after 5 minutes of inactivity, from either inputs I would like to have the output for (let pins = %00010000) light that light for 1/2 second, off 1 second then back on for 1/2 second then delay for 10 min then repeat until the power switch is shut off. This is just a reminder/warning that the power switch is on and needs to be shut off. I have had the power switch inadvertently left in the on position and the battery runs down (after a few days). Thanks for your help!
 

dropdad

Member
One thing I forgot to mention; during the time when the system is in the warning mode (flashing the top light twice for 1/2 second then delaying 10 min) if either input is closed, I would like the system to go to and operate the original programming, but go back to the warning flashes again if again there is a period of inactivity. You also mentioned a way of making the programming more compact. I am really green at this and am open to suggestions and or help. As written though, it's size hasn't been a problem.
Thanks!
dropdad
 

John West

Senior Member
Good on ya, westaus55.

I'd offer some suggestions, dropdad, but I'm not a competent programmer as yet. Give me a year. I don't know if you'll be getting any rapid replies from Australia or GB at this time of night over there. There's a real time zone problem in this world-wide site, as in all such sites. Fortunately, some of these folks never sleep.

I can hardly wait until my own code doesn't work properly and I can come in here and bother everyone with my poorly commented spaghetti. :D
 
Last edited:

westaust55

Moderator
The first feature is very easy to implimernt:
After the Main label you need three lines

Code:
MAIN: 

let pins = %00010000 ; top light on 
PAUSE 1000		   ; wait for 1 second
let pins = %00000000 ; no lights

For the second timing function you seek, this could be achieve but would be much easier with a newer X2 part such as the 20X2 which has a timer function which can cause an interrupt.

With the 18X it can be done a little more primitively by using a loop and going around the loop 300 times with a pause of 1 second plus a check for input activity in each loop.

Whay not at least have a go for yourself first and see what you can do.
We are happy to help get your code running but you will never learn if you make no attempt yourself first.
 
Top